From 7719863ea0593d6d27d45b4b255ecb7d58d435f2 Mon Sep 17 00:00:00 2001
From: Jiaye Wu <161971145+jiaye-wu@users.noreply.github.com>
Date: Fri, 14 Feb 2025 17:16:39 +0100
Subject: [PATCH] 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.
---
_includes/repository/repo.liquid | 24 ++++++++++++++++++++++--
_includes/repository/repo_user.liquid | 24 ++++++++++++++++++++++--
2 files changed, 44 insertions(+), 4 deletions(-)
diff --git a/_includes/repository/repo.liquid b/_includes/repository/repo.liquid
index 0f1afd4..c99b76b 100644
--- a/_includes/repository/repo.liquid
+++ b/_includes/repository/repo.liquid
@@ -5,6 +5,26 @@
{% assign show_owner = true %}
{% 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 %}
{% assign max_lines = site.data.repositories.repo_description_lines_max %}
{% else %}
@@ -16,12 +36,12 @@
diff --git a/_includes/repository/repo_user.liquid b/_includes/repository/repo_user.liquid
index 7dc959f..294d58a 100644
--- a/_includes/repository/repo_user.liquid
+++ b/_includes/repository/repo_user.liquid
@@ -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 %}
+