gitscope
← marzneshin / v0.3.0-alpha2 / 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';
 6import { joinPaths } from '@remix-run/router';
 7
 8declare module 'i18next' {
 9    interface CustomTypeOptions {
10        returnNull: false;
11    }
12}
13
14i18n
15    .use(LanguageDetector)
16    .use(initReactI18next)
17    .use(HttpApi)
18    .init(
19        {
20            debug: import.meta.env.NODE_ENV === 'development',
21            returnNull: false,
22            fallbackLng: 'en',
23            interpolation: {
24                escapeValue: false,
25            },
26            react: {
27                useSuspense: false,
28            },
29            load: 'languageOnly',
30            detection: {
31                caches: ['localStorage', 'sessionStorage', 'cookie'],
32            },
33            backend: {
34                loadPath: joinPaths([import.meta.env.BASE_URL, 'locales/{{lng}}.json']),
35            },
36            supportedLngs: ['en', 'ku-kur', 'ku-sor', 'ku-sor-latin', 'fa', 'ru'],
37        },
38        function() {
39            dayjs.locale(i18n.language);
40        }
41    );
42
43i18n.on('languageChanged', (lng) => {
44    dayjs.locale(lng);
45});
46
47export default i18n;