mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-28 16:56:16 +08:00
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:
@@ -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 (
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user