Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

i18n: a zh-Hant, zh-HK or zh-MO browser opens in Traditional Chinese

Duarte Santos4cd243d8e194
diff --git a/frontend/src/lib/default-lang.js b/frontend/src/lib/default-lang.js
index d8857af47..001b897c1 100644
--- a/frontend/src/lib/default-lang.js
+++ b/frontend/src/lib/default-lang.js
@@ -26,6 +26,9 @@ export function matchLocale(tag) {
const exact = KEYS.find(k => k.toLowerCase() === want)
if (exact) return exact
const base = want.split('-')[0]
+ // Traditional Chinese arrives as zh-Hant(-TW), zh-HK or zh-MO, never as the pack's own 'zh-TW';
+ // the bare base would read it as Simplified.
+ if (base === 'zh' && KEYS.includes('zh-TW') && /^zh-(hant|hk|mo)(-|$)/.test(want)) return 'zh-TW'
return KEYS.includes(base) ? base : null
}
diff --git a/frontend/src/lib/default-lang.test.js b/frontend/src/lib/default-lang.test.js
index 0484ff33b..3d1797cc2 100644
--- a/frontend/src/lib/default-lang.test.js
+++ b/frontend/src/lib/default-lang.test.js
@@ -17,6 +17,16 @@ describe('matchLocale', () => {
expect(matchLocale('')).toBe(null)
expect(matchLocale(undefined)).toBe(null)
})
+ it('reads the Traditional Chinese tags as zh-TW and the rest of Chinese as zh', () => {
+ expect(matchLocale('zh-TW')).toBe('zh-TW')
+ expect(matchLocale('zh-Hant')).toBe('zh-TW')
+ expect(matchLocale('zh-Hant-TW')).toBe('zh-TW')
+ expect(matchLocale('zh-HK')).toBe('zh-TW')
+ expect(matchLocale('zh-MO')).toBe('zh-TW')
+ expect(matchLocale('zh-CN')).toBe('zh')
+ expect(matchLocale('zh-Hans-CN')).toBe('zh')
+ expect(matchLocale('zh')).toBe('zh')
+ })
})
describe('autoLang', () => {