at: Add Chinese language support with new i18n utilities and update routing configura

This commit is contained in:
cxllxc
2025-12-12 12:41:40 +00:00
parent d3fe6b2fcc
commit 3c0fbc8f8f
5 changed files with 563 additions and 8 deletions

View File

@@ -3,17 +3,18 @@ import LanguageDetector from 'i18next-browser-languagedetector';
import HttpBackend from 'i18next-http-backend';
// Supported languages
export const supportedLanguages = ['en', 'de'] as const;
export const supportedLanguages = ['en', 'de', 'zh'] as const;
export type SupportedLanguage = (typeof supportedLanguages)[number];
export const languageNames: Record<SupportedLanguage, string> = {
en: 'English',
de: 'Deutsch',
zh: '中文',
};
export const getLanguageFromUrl = (): SupportedLanguage => {
const path = window.location.pathname;
const langMatch = path.match(/^\/(en|de)(?:\/|$)/);
const langMatch = path.match(/^\/(en|de|zh)(?:\/|$)/);
if (langMatch && supportedLanguages.includes(langMatch[1] as SupportedLanguage)) {
return langMatch[1] as SupportedLanguage;
}
@@ -69,9 +70,9 @@ export const changeLanguage = (lang: SupportedLanguage): void => {
const currentLang = getLanguageFromUrl();
let newPath: string;
if (currentPath.match(/^\/(en|de)\//)) {
newPath = currentPath.replace(/^\/(en|de)\//, `/${lang}/`);
} else if (currentPath.match(/^\/(en|de)$/)) {
if (currentPath.match(/^\/(en|de|zh)\//)) {
newPath = currentPath.replace(/^\/(en|de|zh)\//, `/${lang}/`);
} else if (currentPath.match(/^\/(en|de|zh)$/)) {
newPath = `/${lang}`;
} else {
newPath = `/${lang}${currentPath}`;
@@ -133,7 +134,7 @@ export const rewriteLinks = (): void => {
return;
}
if (href.match(/^\/(en|de)\//)) {
if (href.match(/^\/(en|de|zh)\//)) {
return;
}
let newHref: string;