gitscope
← marzneshin / nightly / 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 "dayjs/locale/fa";
 4import "dayjs/locale/ru";
 5import "dayjs/locale/zh-cn";
 6import "dayjs/locale/ar";
 7import LanguageDetector from 'i18next-browser-languagedetector';
 8import HttpApi from 'i18next-http-backend';
 9import { initReactI18next } from 'react-i18next';
10
11declare module 'i18next' {
12    interface CustomTypeOptions {
13        returnNull: false;
14    }
15}
16
17i18n
18    .use(LanguageDetector)
19    .use(HttpApi)
20    .use(initReactI18next)
21    .init({
22        debug: process.env.NODE_ENV === 'development',
23        fallbackLng: 'en',
24        interpolation: {
25            escapeValue: false,
26        },
27        react: {
28            useSuspense: false,
29        },
30        load: 'languageOnly',
31        detection: {
32            order: ['localStorage', 'sessionStorage', 'cookie', 'navigator'],
33        },
34        backend: {
35            loadPath: `/locales/{{lng}}.json`,
36        },
37        supportedLngs: ['en', 'kur', 'kmr', 'ckb', 'fa', 'ru', 'ar', 'zh-cn'],
38    })
39    .then(() => {
40        dayjs.locale(i18n.language);
41        document.documentElement.lang = i18n.language;
42    });
43
44i18n.on('languageChanged', (lng) => {
45    dayjs.locale(lng);
46    document.documentElement.lang = lng;
47});
48
49export default i18n;