-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi18n.js
More file actions
44 lines (40 loc) · 1.23 KB
/
i18n.js
File metadata and controls
44 lines (40 loc) · 1.23 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
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import * as RNLocalize from "react-native-localize";
import AsyncStorage from '@react-native-async-storage/async-storage';
const languageDetector = {
type: 'languageDetector',
async: true,
detect: async (callback) => {
try {
const storedLang = await AsyncStorage.getItem("lang");
if (storedLang) {
return callback(storedLang.toLowerCase());
}
const locales = RNLocalize.getLocales();
const deviceLang = locales.length > 0 ? locales[0].languageCode : 'tr';
return callback(deviceLang);
} catch (error) {
callback('tr');
}
},
init: () => { },
cacheUserLanguage: (lng) => {
AsyncStorage.setItem("lang", lng.toUpperCase());
},
};
i18n
.use(languageDetector)
.use(initReactI18next)
.init({
resources: {
en: { translation: require("./src/locale/en.json") },
tr: { translation: require("./src/locale/tr.json") },
},
fallbackLng: "tr",
interpolation: {
escapeValue: false,
},
compatibilityJSON: 'v3',
});
export default i18n;