fix language-not-found issues on repo page with simplified and traditional Chinese (#3015)

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".

This patch fixes the problem and has been tested locally & with GitHub
pages.
This commit is contained in:
Jiaye Wu 2025-02-14 17:16:39 +01:00 committed by GitHub
parent 10d007a98c
commit 7719863ea0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 44 additions and 4 deletions

View File

@ -5,6 +5,26 @@
{% assign show_owner = true %} {% assign show_owner = true %}
{% endif %} {% endif %}
{% assign lang = site.lang | split: '-' | first %}
{% case lang %}
{% when 'pt' %}
{% assign lang = site.lang %}
{% when 'zh' %}
{% assign lang_last = site.lang | split: '-' | last %}
{% case lang_last %}
{% when 'cn', 'sg', 'my', 'hans' %}
{% assign lang = 'cn' %}
{% when 'tw', 'hk', 'mo', 'hant' %}
{% assign lang = 'zh-tw' %}
{% endcase %}
{% comment %} Add a new language using when... if needed {% endcomment %}
{% endcase %}
{% 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 %} {% if site.data.repositories.repo_description_lines_max %}
{% assign max_lines = site.data.repositories.repo_description_lines_max %} {% assign max_lines = site.data.repositories.repo_description_lines_max %}
{% else %} {% else %}
@ -16,12 +36,12 @@
<img <img
class="only-light w-100" class="only-light w-100"
alt="{{ include.repository }}" alt="{{ include.repository }}"
src="https://github-readme-stats.vercel.app/api/pin/?username={{ repo_url[0] }}&repo={{ repo_url[1] }}&theme={{ site.repo_theme_light }}&show_owner={{ show_owner }}&description_lines_count={{ max_lines }}" src="https://github-readme-stats.vercel.app/api/pin/?username={{ repo_url[0] }}&repo={{ repo_url[1] }}&theme={{ site.repo_theme_light }}&locale={{ lang }}&show_owner={{ show_owner }}&description_lines_count={{ max_lines }}"
> >
<img <img
class="only-dark w-100" class="only-dark w-100"
alt="{{ include.repository }}" alt="{{ include.repository }}"
src="https://github-readme-stats.vercel.app/api/pin/?username={{ repo_url[0] }}&repo={{ repo_url[1] }}&theme={{ site.repo_theme_dark }}&show_owner={{ show_owner }}&description_lines_count={{ max_lines }}" src="https://github-readme-stats.vercel.app/api/pin/?username={{ repo_url[0] }}&repo={{ repo_url[1] }}&theme={{ site.repo_theme_dark }}&locale={{ lang }}&show_owner={{ show_owner }}&description_lines_count={{ max_lines }}"
> >
</a> </a>
</div> </div>

View File

@ -1,14 +1,34 @@
{% assign lang = site.lang | split: '-' | first %}
{% case lang %}
{% when 'pt' %}
{% assign lang = site.lang %}
{% when 'zh' %}
{% assign lang_last = site.lang | split: '-' | last %}
{% case lang_last %}
{% when 'cn', 'sg', 'my', 'hans' %}
{% assign lang = 'cn' %}
{% when 'tw', 'hk', 'mo', 'hant' %}
{% assign lang = 'zh-tw' %}
{% endcase %}
{% comment %} Add a new language using when... if needed {% endcomment %}
{% endcase %}
{% 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"> <div class="repo p-2 text-center">
<a href="https://github.com/{{ include.username }}"> <a href="https://github.com/{{ include.username }}">
<img <img
class="only-light w-100" class="only-light w-100"
alt="{{ include.username }}" alt="{{ include.username }}"
src="https://github-readme-stats.vercel.app/api/?username={{ include.username }}&theme={{ site.repo_theme_light }}&show_icons=true" src="https://github-readme-stats.vercel.app/api/?username={{ include.username }}&theme={{ site.repo_theme_light }}&locale={{ lang }}&show_icons=true"
> >
<img <img
class="only-dark w-100" class="only-dark w-100"
alt="{{ include.username }}" alt="{{ include.username }}"
src="https://github-readme-stats.vercel.app/api/?username={{ include.username }}&theme={{ site.repo_theme_dark }}&show_icons=true" src="https://github-readme-stats.vercel.app/api/?username={{ include.username }}&theme={{ site.repo_theme_dark }}&locale={{ lang }}&show_icons=true"
> >
</a> </a>
</div> </div>