gitscope
← marzneshin / v0.6.0 / dashboard/src/features/i18n/index.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/features/i18n/index.ts · TypeScript
Blame Raw
 1import dayjs from 'dayjs';
 2import i18n from 'i18next';
 3import LanguageDetector from 'i18next-browser-languagedetector';
 4import HttpApi from 'i18next-http-backend';
 5import { initReactI18next } from 'react-i18next';
 6
 7declare module 'i18next' {
 8    interface CustomTypeOptions {
 9        returnNull: false;
10    }
11}
12
13i18n
14    .use(LanguageDetector)
15    .use(HttpApi)
16    .use(initReactI18next)
17    .init({
18        debug: process.env.NODE_ENV === 'development',
19        fallbackLng: 'en',
20        interpolation: {
21            escapeValue: false,
22        },
23        react: {
24            useSuspense: false,
25        },
26        load: 'languageOnly',
27        detection: {
28            order: ['localStorage', 'sessionStorage', 'cookie', 'navigator'],
29        },
30        backend: {
31            loadPath: `/locales/{{lng}}.json`,
32        },
33        supportedLngs: ['en', 'kur', 'kmr', 'ckb', 'fa', 'ru'],
34    })
35    .then(() => {
36        dayjs.locale(i18n.language);
37    });
38
39i18n.on('languageChanged', (lng) => {
40    dayjs.locale(lng);
41});
42
43export default i18n;