all repos — caroster @ 392f026c797ca85247bf71cdef9b86c274532e60

[Octree] Group carpool to your event https://caroster.io

frontend/lib/i18n.ts (view raw)

 1import i18n from 'i18next';
 2import {initReactI18next} from 'react-i18next';
 3import 'moment/min/locales';
 4import moment from 'moment';
 5import {InContextTools} from '@tolgee/web/tools';
 6import {withTolgee, Tolgee, I18nextPlugin, BackendFetch} from '@tolgee/i18next';
 7import {Enum_Userspermissionsuser_Lang as SupportedLocales} from '../generated/graphql';
 8import translationFr from '../locales/fr.json';
 9import translationEn from '../locales/en.json';
10import translationNl from '../locales/nl.json';
11
12const resources = {
13  en: {
14    translation: translationEn,
15  },
16  fr: {
17    translation: translationFr,
18  },
19
20  nl: {
21    translation: translationNl,
22  },
23};
24
25const tolgee = Tolgee()
26  .use(InContextTools())
27  .use(I18nextPlugin())
28  .init({
29    // for development
30    apiUrl: process.env.NEXT_PUBLIC_TOLGEE_API_URL,
31    apiKey: process.env.NEXT_PUBLIC_TOLGEE_API_KEY,
32    ns: ['translation'],
33  });
34
35export const initI18Next = (locale: SupportedLocales) => {
36  withTolgee(i18n, tolgee)
37    .use(initReactI18next) // passes i18n down to react-i18next
38    .init({
39      resources,
40      lng: locale,
41      supportedLngs: ['fr', 'en', 'nl'],
42      fallbackLng: 'en',
43      defaultNS: 'translation',
44      interpolation: {
45        escapeValue: false, // react already safes from xss
46      },
47    });
48  moment.locale(i18n.language);
49};
50
51export default i18n;