-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi18n.tsx
44 lines (38 loc) · 988 Bytes
/
i18n.tsx
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 i18next from "i18next";
import { initReactI18next } from "react-i18next";
import AsyncStorage from "@react-native-async-storage/async-storage";
import en from "./locales/en.json";
import ru from "./locales/ru.json";
const resources = {
en: {
translation: en,
},
ru: {
translation: ru,
},
};
const getDeviceLanguage = () => {
const language = navigator.language || navigator.languages[0];
if (language.startsWith('ru')) {
return 'ru';
}
return 'en';
};
const loadLanguage = async () => {
const savedLanguage = await AsyncStorage.getItem("language");
return savedLanguage || getDeviceLanguage();
};
loadLanguage().then((language) => {
console.log("loadLanguage")
i18next
.use(initReactI18next)
.init({
compatibilityJSON: "v3",
resources: resources,
lng: language,
fallbackLng: "en",
interpolation: { escapeValue: false },
});
console.log("loadLanguage: " + language)
});
export default i18next;