-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathi18n.js
More file actions
63 lines (53 loc) · 1.46 KB
/
i18n.js
File metadata and controls
63 lines (53 loc) · 1.46 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import i18n from 'i18next';
import {initReactI18next} from 'react-i18next';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {en} from './assets/langs/en';
import {ar} from './assets/langs/ar';
import {de} from './assets/langs/de';
import {es} from './assets/langs/es';
import {fr} from './assets/langs/fr';
import {ie} from './assets/langs/ie';
import {nl} from './assets/langs/nl';
import {pt} from './assets/langs/pt';
const LANGUAGE_KEY = 'user_language';
const resources = {
en: {translation: en},
ar: {translation: ar},
de: {translation: de},
es: {translation: es},
fr: {translation: fr},
ie: {translation: ie},
nl: {translation: nl},
pt: {translation: pt}
};
// Custom language detector that persists to AsyncStorage
const languageDetector = {
type: 'languageDetector',
async: true,
detect: async (callback) => {
try {
const saved = await AsyncStorage.getItem(LANGUAGE_KEY);
callback(saved || 'en');
} catch {
callback('en');
}
},
init: () => {},
cacheUserLanguage: async (lng) => {
try {
await AsyncStorage.setItem(LANGUAGE_KEY, lng);
} catch {}
}
};
i18n.use(languageDetector).use(initReactI18next).init({
compatibilityJSON: 'v3',
resources,
fallbackLng: 'en',
interpolation: {
escapeValue: false
},
react: {
useSuspense: false
}
});
export default i18n;