feat(i18n): add Traditional Chinese localization (#3093)

* Add Traditional Chinese localization

* fix: address zh-TW formatting and token units

- Format `zh-TW.json` with Prettier.
- Use Traditional Chinese `萬` and `億` units for zh-TW token summaries.
- Add usage formatting coverage for Traditional Chinese locale aliases.

---------

Co-authored-by: Jason <farion1231@gmail.com>
This commit is contained in:
滅ü
2026-05-27 00:05:03 +08:00
committed by GitHub
parent 8cdaf90d8d
commit 5fd3ec0d6a
16 changed files with 2795 additions and 21 deletions
+5 -3
View File
@@ -22,9 +22,11 @@ export function RequestDetailPanel({
const dateLocale =
i18n.language === "zh"
? "zh-CN"
: i18n.language === "ja"
? "ja-JP"
: "en-US";
: i18n.language === "zh-TW"
? "zh-TW"
: i18n.language === "ja"
? "ja-JP"
: "en-US";
if (isLoading) {
return (
+27 -3
View File
@@ -31,10 +31,28 @@ export function fmtUsd(
return `$${num.toFixed(digits)}`;
}
function normalizeLanguageTag(language: string): string {
return language.toLowerCase().replace(/_/g, "-");
}
function isTraditionalChineseLanguage(normalizedLanguage: string): boolean {
return (
normalizedLanguage === "zh-tw" ||
normalizedLanguage.startsWith("zh-hant") ||
normalizedLanguage.startsWith("zh-hk") ||
normalizedLanguage.startsWith("zh-mo")
);
}
export function getLocaleFromLanguage(language: string): string {
if (!language) return "en-US";
if (language.startsWith("zh")) return "zh-CN";
if (language.startsWith("ja")) return "ja-JP";
const normalized = normalizeLanguageTag(language);
if (normalized === "zh") return "zh-CN";
if (isTraditionalChineseLanguage(normalized)) {
return "zh-TW";
}
if (normalized.startsWith("zh")) return "zh-CN";
if (normalized.startsWith("ja")) return "ja-JP";
return "en-US";
}
@@ -61,7 +79,13 @@ export function formatTokensShort(
): string {
if (!Number.isFinite(value) || value <= 0) return "0";
const decimals = compactDecimals;
if (lang.startsWith("zh") || lang.startsWith("ja")) {
const normalizedLang = normalizeLanguageTag(lang);
if (isTraditionalChineseLanguage(normalizedLang)) {
if (value >= 1e8) return `${(value / 1e8).toFixed(2)}`;
if (value >= 1e4) return `${(value / 1e4).toFixed(decimals)}`;
return value.toLocaleString("zh-TW");
}
if (normalizedLang.startsWith("zh") || normalizedLang.startsWith("ja")) {
if (value >= 1e8) return `${(value / 1e8).toFixed(2)} 亿`;
if (value >= 1e4) return `${(value / 1e4).toFixed(decimals)}`;
return value.toLocaleString();