Skip to content

Commit

Permalink
fix language-not-found issues on repo page with simplified and tradit…
Browse files Browse the repository at this point in the history
…ional Chinese

The author of github-readme-stats uses the non-standard code "cn" for simplified Chinese, see [here](https://github.com/anuraghazra/github-readme-stats?tab=readme-ov-file#available-locales). While for traditional Chinese the author only provides "zh-tw". The github-readme-stats functions on repo page will break if the user sets the site language to ALL variants of Chinese except for zh-tw. This hack is to make all sub-variants of simplified Chinese fall back to "cn" and all sub-variants of traditional Chinese fall back to "zh-tw".
  • Loading branch information
jiaye-wu committed Feb 13, 2025
1 parent 10d007a commit edb96ae
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions _includes/repository/repo.liquid
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
{% assign show_owner = true %}
{% endif %}

{% assign lang = site.active_lang | split: '-' | first %}
{% if lang == 'pt' %}
{% assign lang = site.active_lang %}
{% endif %}
{% if lang == 'zh' %}
{% assign lang_last = site.active_lang | split: '-' | last %}
{% if lang_last == 'cn' or lang_last == 'sg' or lang_last == 'my' or lang_last == 'hans' %}
{% assign lang = 'cn' %}
{% elsif lang_last == 'tw' or lang_last == 'hk' or lang_last == 'mo' or lang_last == 'hant' %}
{% assign lang = 'zh-tw' %}
{% endif %}
{% endif %}
{% comment %} If you still encounter language-display issues, check the available locale codes in github-readme-stats (different from ISO-639 standard used in your website): https://github.com/anuraghazra/github-readme-stats?tab=readme-ov-file#available-locales {% endcomment %}

{% if site.data.repositories.repo_description_lines_max %}
{% assign max_lines = site.data.repositories.repo_description_lines_max %}
{% else %}
Expand Down
14 changes: 14 additions & 0 deletions _includes/repository/repo_user.liquid
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
{% assign lang = site.active_lang | split: '-' | first %}
{% if lang == 'pt' %}
{% assign lang = site.active_lang %}
{% endif %}
{% if lang == 'zh' %}
{% assign lang_last = site.active_lang | split: '-' | last %}
{% if lang_last == 'cn' or lang_last == 'sg' or lang_last == 'my' or lang_last == 'hans' %}
{% assign lang = 'cn' %}
{% elsif lang_last == 'tw' or lang_last == 'hk' or lang_last == 'mo' or lang_last == 'hant' %}
{% assign lang = 'zh-tw' %}
{% endif %}
{% endif %}
{% comment %} If you still encounter language-display issues, check the available locale codes in github-readme-stats (different from ISO-639 standard used in your website): https://github.com/anuraghazra/github-readme-stats?tab=readme-ov-file#available-locales {% endcomment %}

<div class="repo p-2 text-center">
<a href="https://github.com/{{ include.username }}">
<img
Expand Down

0 comments on commit edb96ae

Please sign in to comment.