feat: i18n
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
import en from './locales/en';
|
||||
import ru from './locales/ru';
|
||||
|
||||
const STORAGE_KEY = 'mcma_lang';
|
||||
|
||||
function detectLanguage(): string {
|
||||
const stored = localStorage.getItem(STORAGE_KEY);
|
||||
if (stored) return stored;
|
||||
const browser = navigator.language.split('-')[0];
|
||||
return browser === 'ru' ? 'ru' : 'en';
|
||||
}
|
||||
|
||||
export function setLanguage(lang: string): void {
|
||||
localStorage.setItem(STORAGE_KEY, lang);
|
||||
void i18n.changeLanguage(lang);
|
||||
}
|
||||
|
||||
export const SUPPORTED_LANGUAGES = [
|
||||
{ code: 'en', label: 'English' },
|
||||
{ code: 'ru', label: 'Русский' },
|
||||
] as const;
|
||||
|
||||
void i18n.use(initReactI18next).init({
|
||||
resources: {
|
||||
en: { translation: en },
|
||||
ru: { translation: ru },
|
||||
},
|
||||
lng: detectLanguage(),
|
||||
fallbackLng: 'en',
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
Reference in New Issue
Block a user