forked from technoforte/inji
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i18n.ts
45 lines (39 loc) · 1.13 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 i18next from 'i18next';
import { locale } from 'expo-localization';
import { initReactI18next } from 'react-i18next';
import en from './locales/en.json';
import fil from './locales/fil.json';
import ar from './locales/ara.json';
import hi from './locales/hin.json';
import kn from './locales/kan.json';
import ta from './locales/tam.json';
import AsyncStorage from '@react-native-async-storage/async-storage';
const resources = { en, fil, ar, hi, kn, ta };
export const SUPPORTED_LANGUAGES = {
en: 'English',
fil: 'Filipino',
ar: 'عربى',
hi: 'हिंदी',
kn: 'ಕನ್ನಡ',
ta: 'தமிழ்',
};
i18next
.use(initReactI18next)
.init({
compatibilityJSON: 'v3',
resources,
lng: getLanguageCode(locale),
fallbackLng: getLanguageCode,
supportedLngs: Object.keys(SUPPORTED_LANGUAGES),
})
.then(async () => {
const language = await AsyncStorage.getItem('language');
if (language !== i18next.language) {
i18next.changeLanguage(language);
}
});
export default i18next;
function getLanguageCode(code: string) {
const [language] = code.split('-');
return language;
}