add tr lang

This commit is contained in:
Hasan Tekgül
2025-12-19 18:17:04 +03:00
committed by Hasan TEKGÜL
parent 2417168fb9
commit 33e558b290
5 changed files with 609 additions and 8 deletions

View File

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