-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
63 lines (57 loc) · 1.46 KB
/
App.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import i18next from "i18next";
import { StatusBar } from "expo-status-bar";
import { initReactI18next, useTranslation } from "react-i18next";
import { AppState, StyleSheet, Text, View } from "react-native";
import i18nextHttpBackend, { HttpBackendOptions } from "i18next-http-backend";
import { useEffect } from "react";
i18next
.use(initReactI18next)
.use(i18nextHttpBackend)
.init<HttpBackendOptions>({
backend: {
loadPath: "https://random-data-api.com/api/v2/users",
parse(data) {
console.log("called parse");
return JSON.parse(data);
},
},
lng: "en",
fallbackLng: "en",
defaultNS: "translation",
ns: ["translation"],
react: {
useSuspense: false,
},
compatibilityJSON: "v3",
debug: true,
});
export default function App() {
const { t } = useTranslation();
useEffect(() => {
const listener = AppState.addEventListener("change", (state) => {
if (state === "active") {
i18next.reloadResources().then(() => {
console.log("reloaded");
i18next.changeLanguage("en");
});
}
});
return () => {
listener.remove();
};
}, []);
return (
<View style={styles.container}>
<Text>first name: {t("first_name")}</Text>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});