29 lines
804 B
TypeScript
29 lines
804 B
TypeScript
|
|
import i18n from 'i18next';
|
||
|
|
import { initReactI18next } from 'react-i18next';
|
||
|
|
|
||
|
|
import en from './locales/en.json';
|
||
|
|
import ru from './locales/ru.json';
|
||
|
|
|
||
|
|
export const defaultNS = 'translation';
|
||
|
|
export const supportedLanguages = ['ru', 'en'] as const;
|
||
|
|
export type SupportedLanguage = (typeof supportedLanguages)[number];
|
||
|
|
|
||
|
|
const storedLanguage =
|
||
|
|
typeof window === 'undefined' ? null : window.localStorage.getItem('glchat.language');
|
||
|
|
|
||
|
|
const initialLanguage: SupportedLanguage =
|
||
|
|
storedLanguage === 'en' || storedLanguage === 'ru' ? storedLanguage : 'ru';
|
||
|
|
|
||
|
|
void i18n.use(initReactI18next).init({
|
||
|
|
resources: {
|
||
|
|
ru: { translation: ru },
|
||
|
|
en: { translation: en },
|
||
|
|
},
|
||
|
|
lng: initialLanguage,
|
||
|
|
fallbackLng: 'ru',
|
||
|
|
interpolation: { escapeValue: false },
|
||
|
|
returnNull: false,
|
||
|
|
});
|
||
|
|
|
||
|
|
export default i18n;
|