Repository navigation
feat(cli): add Traditional Chinese (zh-TW) as a UI language option #3569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 15 commits
28e1600
d849354
3d542a0
bcc92ea
cb51281
89c4955
ccbde3d
e3db54c
3374d47
3555bd5
1382c3a
0bd40bc
fc23c1e
7eedd5f
522aad4
c8d4fae
a5c3ed9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |||||
| export type SupportedLanguage = | ||||||
| | 'en' | ||||||
| | 'zh' | ||||||
| | 'zh-TW' | ||||||
| | 'ru' | ||||||
| | 'de' | ||||||
| | 'ja' | ||||||
|
|
@@ -32,6 +33,12 @@ export const SUPPORTED_LANGUAGES: readonly LanguageDefinition[] = [ | |||||
| fullName: 'English', | ||||||
| nativeName: 'English', | ||||||
| }, | ||||||
| { | ||||||
| code: 'zh-TW', | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] Adding
Suggested change
Alternatively, keep the canonical code and make — gpt-5.5 via Qwen Code /review |
||||||
| id: 'zh-TW', | ||||||
| fullName: 'Traditional Chinese', | ||||||
| nativeName: '繁體中文', | ||||||
| }, | ||||||
| { | ||||||
| code: 'zh', | ||||||
| id: 'zh-CN', | ||||||
|
|
||||||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,6 @@ import { fileURLToPath } from 'url'; | |||||
| import { dirname } from 'path'; | ||||||
|
|
||||||
| // Get __dirname for ESM modules | ||||||
| // @ts-expect-error - import.meta is supported in NodeNext module system at runtime | ||||||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||||||
|
|
||||||
| interface CheckResult { | ||||||
|
|
@@ -23,6 +22,7 @@ interface CheckResult { | |||||
| stats: { | ||||||
| totalKeys: number; | ||||||
| translatedKeys: number; | ||||||
| zhTWTranslatedKeys: number; | ||||||
| unusedKeys: string[]; | ||||||
| unusedKeysOnlyInLocales?: string[]; // 新增:只在 locales 中存在的未使用键 | ||||||
| }; | ||||||
|
|
@@ -172,27 +172,31 @@ function checkKeyValueConsistency( | |||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Check if en.js and zh.js have matching keys | ||||||
| * Check if locale files have matching keys with en.js | ||||||
| * @param enTranslations The en.js translations | ||||||
| * @param localeTranslations The target locale translations (zh.js or zh-TW.js) | ||||||
| * @param localeLabel Label for diagnostics (e.g., "zh.js" or "zh-TW.js") | ||||||
| */ | ||||||
| function checkKeyMatching( | ||||||
| enTranslations: Record<string, string | string[]>, | ||||||
| zhTranslations: Record<string, string | string[]>, | ||||||
| localeTranslations: Record<string, string | string[]>, | ||||||
| localeLabel: string, | ||||||
| ): string[] { | ||||||
| const errors: string[] = []; | ||||||
| const enKeys = new Set(Object.keys(enTranslations)); | ||||||
| const zhKeys = new Set(Object.keys(zhTranslations)); | ||||||
| const localeKeys = new Set(Object.keys(localeTranslations)); | ||||||
|
|
||||||
| // Check for keys in en but not in zh | ||||||
| // Check for keys in en but not in locale | ||||||
| for (const key of enKeys) { | ||||||
| if (!zhKeys.has(key)) { | ||||||
| errors.push(`Missing translation in zh.js: "${key}"`); | ||||||
| if (!localeKeys.has(key)) { | ||||||
| errors.push(`Missing translation in ${localeLabel}: "${key}"`); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| // Check for keys in zh but not in en | ||||||
| for (const key of zhKeys) { | ||||||
| // Check for keys in locale but not in en | ||||||
| for (const key of localeKeys) { | ||||||
| if (!enKeys.has(key)) { | ||||||
| errors.push(`Extra key in zh.js (not in en.js): "${key}"`); | ||||||
| errors.push(`Extra key in ${localeLabel} (not in en.js): "${key}"`); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -304,10 +308,12 @@ async function checkI18n(): Promise<CheckResult> { | |||||
|
|
||||||
| const enPath = path.join(localesDir, 'en.js'); | ||||||
| const zhPath = path.join(localesDir, 'zh.js'); | ||||||
| const zhTWPath = path.join(localesDir, 'zh-TW.js'); | ||||||
|
|
||||||
| // Load translation files | ||||||
| let enTranslations: Record<string, string | string[]>; | ||||||
| let zhTranslations: Record<string, string | string[]>; | ||||||
| let zhTWTranslations: Record<string, string | string[]>; | ||||||
|
|
||||||
| try { | ||||||
| enTranslations = await loadTranslationsFile(enPath); | ||||||
|
|
@@ -319,7 +325,12 @@ async function checkI18n(): Promise<CheckResult> { | |||||
| success: false, | ||||||
| errors, | ||||||
| warnings, | ||||||
| stats: { totalKeys: 0, translatedKeys: 0, unusedKeys: [] }, | ||||||
| stats: { | ||||||
| totalKeys: 0, | ||||||
| translatedKeys: 0, | ||||||
| zhTWTranslatedKeys: 0, | ||||||
| unusedKeys: [], | ||||||
| }, | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -333,7 +344,31 @@ async function checkI18n(): Promise<CheckResult> { | |||||
| success: false, | ||||||
| errors, | ||||||
| warnings, | ||||||
| stats: { totalKeys: 0, translatedKeys: 0, unusedKeys: [] }, | ||||||
| stats: { | ||||||
| totalKeys: 0, | ||||||
| translatedKeys: 0, | ||||||
| zhTWTranslatedKeys: 0, | ||||||
| unusedKeys: [], | ||||||
| }, | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
| try { | ||||||
| zhTWTranslations = await loadTranslationsFile(zhTWPath); | ||||||
| } catch (error) { | ||||||
| errors.push( | ||||||
| `Failed to load zh-TW.js: ${error instanceof Error ? error.message : String(error)}`, | ||||||
| ); | ||||||
| return { | ||||||
| success: false, | ||||||
| errors, | ||||||
| warnings, | ||||||
| stats: { | ||||||
| totalKeys: 0, | ||||||
| translatedKeys: 0, | ||||||
| zhTWTranslatedKeys: 0, | ||||||
| unusedKeys: [], | ||||||
| }, | ||||||
| }; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -342,9 +377,21 @@ async function checkI18n(): Promise<CheckResult> { | |||||
| errors.push(...consistencyErrors); | ||||||
|
|
||||||
| // Check key matching between en and zh | ||||||
| const matchingErrors = checkKeyMatching(enTranslations, zhTranslations); | ||||||
| const matchingErrors = checkKeyMatching( | ||||||
| enTranslations, | ||||||
| zhTranslations, | ||||||
| 'zh.js', | ||||||
| ); | ||||||
| errors.push(...matchingErrors); | ||||||
|
|
||||||
| // Check key matching between en and zh-TW | ||||||
| const matchingTWErrors = checkKeyMatching( | ||||||
| enTranslations, | ||||||
| zhTWTranslations, | ||||||
| 'zh-TW.js', | ||||||
| ); | ||||||
| errors.push(...matchingTWErrors); | ||||||
|
|
||||||
| // Extract used keys from source code | ||||||
| const usedKeys = await extractUsedKeys(sourceDir); | ||||||
|
|
||||||
|
|
@@ -363,15 +410,17 @@ async function checkI18n(): Promise<CheckResult> { | |||||
| } | ||||||
|
|
||||||
| const totalKeys = Object.keys(enTranslations).length; | ||||||
| const translatedKeys = Object.keys(zhTranslations).length; | ||||||
| const zhTranslatedKeys = Object.keys(zhTranslations).length; | ||||||
| const zhTWTranslatedKeys = Object.keys(zhTWTranslations).length; | ||||||
|
|
||||||
| return { | ||||||
| success: errors.length === 0, | ||||||
| errors, | ||||||
| warnings, | ||||||
| stats: { | ||||||
| totalKeys, | ||||||
| translatedKeys, | ||||||
| translatedKeys: zhTranslatedKeys, | ||||||
| zhTWTranslatedKeys, | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Critical] The returned
Suggested change
— gpt-5.4 via Qwen Code /review |
||||||
| unusedKeys, | ||||||
| unusedKeysOnlyInLocales, | ||||||
| }, | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Critical] Adding
zh-TWafter the genericzhentry breaks the new locale for users who keepgeneral.languageonauto.detectSystemLanguage()walksSUPPORTED_LANGUAGESin order and usesstartsWith(), sozh-TW/zh-TW.UTF-8matcheszhfirst and still resolves to Simplified Chinese.— gpt-5.4 via Qwen Code /review