Skip to content

Commit

Permalink
chore: Setup i18n.
Browse files Browse the repository at this point in the history
  • Loading branch information
willtp87 committed May 12, 2024
1 parent 43cb79f commit 1da3651
Show file tree
Hide file tree
Showing 7 changed files with 411 additions and 714 deletions.
6 changes: 5 additions & 1 deletion App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { ThemeProvider, Text, createTheme } from "@rneui/themed";
import { StatusBar } from "expo-status-bar";
import React from "react";
import "intl-pluralrules";
import "./i18n/i18n";
import { useTranslation } from "react-i18next";
import { StyleSheet, View } from "react-native";

const theme = createTheme({});

export default function App() {
const { t } = useTranslation();
return (
<ThemeProvider theme={theme}>
<View style={styles.container}>
<Text>Panting template repo!</Text>
<Text>{t("helloWorld")}</Text>
<StatusBar style="auto" />
</View>
</ThemeProvider>
Expand Down
21 changes: 21 additions & 0 deletions i18n/i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { getLocales } from "expo-localization";
import i18n from "i18next";
import { initReactI18next } from "react-i18next";

import englishTranslation from "./locales/english.json";
import frenchTranslation from "./locales/french.json";

i18n.use(initReactI18next).init({
lng: getLocales().find(() => true)?.languageCode ?? "",
resources: {
en: {
translation: englishTranslation,
},
fr: {
translation: frenchTranslation,
},
},
fallbackLng: ["en"],
});

export default i18n;
3 changes: 3 additions & 0 deletions i18n/locales/english.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"helloWorld": "Panting template repo!"
}
3 changes: 3 additions & 0 deletions i18n/locales/french.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"helloWorld": "Panting dépôt de modèles."
}
7 changes: 7 additions & 0 deletions jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
// set/clear Immediate not available by default.
global.setImmediate = jest.useRealTimers as unknown as typeof setImmediate;
global.clearImmediate = jest.useRealTimers as unknown as typeof clearImmediate;
// https://github.com/expo/expo/issues/27496
jest.mock("expo-localization", () => ({
getLocales: jest.fn(() => {
return [{ languageCode: "en" }];
}),
}));
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
"dependencies": {
"@rneui/base": "^4.0.0-rc.8",
"@rneui/themed": "^4.0.0-rc.8",
"expo": "~50.0.14",
"expo": "~51",
"expo-localization": "^15.0.3",
"expo-status-bar": "~1.11.1",
"i18next": "^23.11.4",
"intl-pluralrules": "^2.0.1",
"react": "18.2.0",
"react-i18next": "^14.1.1",
"react-native": "0.73.6",
"react-native-safe-area-context": "^4.10.1",
"typescript": "^5.3.0"
Expand Down
1,079 changes: 367 additions & 712 deletions yarn.lock

Large diffs are not rendered by default.

0 comments on commit 1da3651

Please sign in to comment.