Merge branch 'main' into main

This commit is contained in:
zhenyao xu
2025-12-12 19:14:25 +00:00
committed by GitHub
81 changed files with 658 additions and 17 deletions

View File

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