gitscope
← marzneshin / v0.2.1 / app/dashboard/src/locales/i18n.ts
https://dev.kronoz.win/r/marzneshin.git
app/dashboard/src/locales/i18n.ts · TypeScript
Blame Raw
 1import { joinPaths } from '@remix-run/router';
 2
 3import fa from 'date-fns/locale/fa-IR';
 4import ru from 'date-fns/locale/ru';
 5import zh from 'date-fns/locale/zh-CN';
 6import dayjs from 'dayjs';
 7import i18n from 'i18next';
 8import LanguageDetector from 'i18next-browser-languagedetector';
 9import HttpApi from 'i18next-http-backend';
10import { registerLocale } from 'react-datepicker';
11import { initReactI18next } from 'react-i18next';
12
13declare module 'i18next' {
14  interface CustomTypeOptions {
15    returnNull: false;
16  }
17}
18
19i18n
20  .use(LanguageDetector)
21  .use(initReactI18next)
22  .use(HttpApi)
23  .init(
24    {
25      debug: import.meta.env.NODE_ENV === 'development',
26      returnNull: false,
27      fallbackLng: 'en',
28      interpolation: {
29        escapeValue: false,
30      },
31      react: {
32        useSuspense: false,
33      },
34      load: 'languageOnly',
35      detection: {
36        caches: ['localStorage', 'sessionStorage', 'cookie'],
37      },
38      backend: {
39        loadPath: joinPaths([import.meta.env.BASE_URL, 'locales/{{lng}}.json']),
40      },
41    },
42    function() {
43      dayjs.locale(i18n.language);
44    }
45  );
46
47i18n.on('languageChanged', (lng) => {
48  dayjs.locale(lng);
49});
50
51// DataPicker
52registerLocale('zh-cn', zh);
53registerLocale('ru', ru);
54registerLocale('fa', fa);
55
56export default i18n;