-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n.ts
45 lines (40 loc) · 1.22 KB
/
i18n.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import { IframeMessageProxy } from 'iframe-message-proxy';
import enTranslation from '../../assets/locales/en/translation.json';
import esTranslation from '../../assets/locales/es/translation.json';
import ptTranslation from '../../assets/locales/pt/translation.json';
i18n
.use(initReactI18next)
.use({
type: 'languageDetector',
async: true,
detect: async (callback: (language: string) => void) => {
const { response } = (await IframeMessageProxy.sendMessage({
action: 'getCurrentLanguage',
})) as { response: string | undefined };
const fallback = 'pt';
const language = response ?? fallback;
const isSupported = ['en', 'es', 'pt'].includes(language);
callback(isSupported ? language : fallback);
},
})
.init({
resources: {
en: { translation: enTranslation },
es: { translation: esTranslation },
pt: { translation: ptTranslation },
},
fallbackLng: 'pt',
interpolation: {
escapeValue: false,
},
});
declare module 'i18next' {
interface CustomTypeOptions {
resources: {
translation: typeof enTranslation;
};
}
}
export default i18n;