Add Traditional Chinese (zh-TW) localization

This commit is contained in:
NightFeather
2026-01-11 03:19:45 +08:00
parent 01f5aca5aa
commit 1ac0f751e8
6 changed files with 613 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ export const supportedLanguages = [
'en',
'de',
'zh',
'zh-TW',
'vi',
'tr',
'id',
@@ -18,6 +19,7 @@ export const languageNames: Record<SupportedLanguage, string> = {
en: 'English',
de: 'Deutsch',
zh: '中文',
"zh-TW": '繁體中文(台灣)',
vi: 'Tiếng Việt',
tr: 'Türkçe',
id: 'Bahasa Indonesia',
@@ -26,7 +28,7 @@ export const languageNames: Record<SupportedLanguage, string> = {
export const getLanguageFromUrl = (): SupportedLanguage => {
const path = window.location.pathname;
const langMatch = path.match(/^\/(en|de|zh|vi|tr|id|it)(?:\/|$)/);
const langMatch = path.match(/^\/(en|de|zh|zh-TW|vi|tr|id|it)(?:\/|$)/);
if (
langMatch &&
supportedLanguages.includes(langMatch[1] as SupportedLanguage)
@@ -88,9 +90,9 @@ export const changeLanguage = (lang: SupportedLanguage): void => {
const currentLang = getLanguageFromUrl();
let newPath: string;
if (currentPath.match(/^\/(en|de|zh|vi|tr|id|it)\//)) {
newPath = currentPath.replace(/^\/(en|de|zh|vi|tr|id|it)\//, `/${lang}/`);
} else if (currentPath.match(/^\/(en|de|zh|vi|tr|id|it)$/)) {
if (currentPath.match(/^\/(en|de|zh|zh-TW|vi|tr|id|it)\//)) {
newPath = currentPath.replace(/^\/(en|de|zh|zh-TW|vi|tr|id|it)\//, `/${lang}/`);
} else if (currentPath.match(/^\/(en|de|zh|zh-TW|vi|tr|id|it)$/)) {
newPath = `/${lang}`;
} else {
newPath = `/${lang}${currentPath}`;
@@ -154,7 +156,7 @@ export const rewriteLinks = (): void => {
return;
}
if (href.match(/^\/(en|de|zh|vi|tr|id|it)\//)) {
if (href.match(/^\/(en|de|zh|zh-TW|vi|tr|id|it)\//)) {
return;
}
let newHref: string;