Merge branch 'main' into main
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -95,7 +95,7 @@ export const injectLanguageSwitcher = (): void => {
|
||||
let followUsColumn: HTMLElement | null = null;
|
||||
|
||||
headings.forEach((h3) => {
|
||||
if (h3.textContent?.trim() === 'Follow Us' || h3.textContent?.trim() === 'Folgen Sie uns') {
|
||||
if (h3.textContent?.trim() === 'Follow Us' || h3.textContent?.trim() === 'Folgen Sie uns' || h3.textContent?.trim() === 'Theo dõi chúng tôi') {
|
||||
followUsColumn = h3.parentElement;
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user