From 869c1fbe51798110874224bc60e55148f9bfb2d2 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Tue, 6 Dec 2022 15:13:04 +0900 Subject: [PATCH] Add react native translation --- front/apps/mobile/app/_layout.tsx | 20 ++++++++++++++++++++ front/apps/mobile/package.json | 2 ++ front/apps/web/src/i18n.tsx | 1 - front/yarn.lock | 27 +++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/front/apps/mobile/app/_layout.tsx b/front/apps/mobile/app/_layout.tsx index 98e9b1ce..595467f3 100644 --- a/front/apps/mobile/app/_layout.tsx +++ b/front/apps/mobile/app/_layout.tsx @@ -25,6 +25,26 @@ import { NavbarTitle } from "@kyoo/ui"; import { useState } from "react"; import { QueryClientProvider } from "@tanstack/react-query"; import { createQueryClient } from "@kyoo/models"; +import i18next from "i18next"; +import { initReactI18next } from "react-i18next"; +import { getLocales } from "expo-localization"; +import "intl-pluralrules"; + +// TODO: use a backend to load jsons. +import en from "../../../translations/en.json"; +import fr from "../../../translations/fr.json"; + +i18next.use(initReactI18next).init({ + interpolation: { + escapeValue: false, + }, + fallbackLng: "en", + lng: getLocales()[0].languageCode, + resources: { + en: { translation: en }, + fr: { translation: fr }, + }, +}); const ThemedStack = () => { const theme = useTheme(); diff --git a/front/apps/mobile/package.json b/front/apps/mobile/package.json index 29511949..a7490199 100644 --- a/front/apps/mobile/package.json +++ b/front/apps/mobile/package.json @@ -15,9 +15,11 @@ "expo-constants": "~14.0.2", "expo-linear-gradient": "~12.0.1", "expo-linking": "~3.2.3", + "expo-localization": "~14.0.0", "expo-router": "^0.0.36", "expo-status-bar": "~1.4.2", "i18next": "^22.0.6", + "intl-pluralrules": "^1.3.1", "moti": "^0.21.0", "react": "18.1.0", "react-dom": "18.1.0", diff --git a/front/apps/web/src/i18n.tsx b/front/apps/web/src/i18n.tsx index f9d49c81..bf4c6bdc 100644 --- a/front/apps/web/src/i18n.tsx +++ b/front/apps/web/src/i18n.tsx @@ -33,7 +33,6 @@ export const withTranslations = ( ) => { const i18n = i18next.createInstance(); const commonOptions: InitOptions = { - debug: true, interpolation: { escapeValue: false, }, diff --git a/front/yarn.lock b/front/yarn.lock index d9e36c50..50908e38 100644 --- a/front/yarn.lock +++ b/front/yarn.lock @@ -6354,6 +6354,17 @@ __metadata: languageName: node linkType: hard +"expo-localization@npm:~14.0.0": + version: 14.0.0 + resolution: "expo-localization@npm:14.0.0" + dependencies: + rtl-detect: ^1.0.2 + peerDependencies: + expo: "*" + checksum: b1107fec3ce98386b21a1ed3adad279559cc24d07403ff32e4253e337f1018a115b265d471f374f76515c3ca6b0b73e132eff7783f51bd248908da3ca3c269a6 + languageName: node + linkType: hard + "expo-modules-autolinking@npm:*, expo-modules-autolinking@npm:1.0.0": version: 1.0.0 resolution: "expo-modules-autolinking@npm:1.0.0" @@ -7615,6 +7626,13 @@ __metadata: languageName: node linkType: hard +"intl-pluralrules@npm:^1.3.1": + version: 1.3.1 + resolution: "intl-pluralrules@npm:1.3.1" + checksum: b22c2373b6b658e5a361d9d1e9a3d4478862a79a9723b910d29745ff6b5b78d8e1e10c47f344bd3835219b77d2f6cfd58388c1bab3b5daf4df72555e02342b40 + languageName: node + linkType: hard + "invariant@npm:^2.2.4": version: 2.2.4 resolution: "invariant@npm:2.2.4" @@ -9625,9 +9643,11 @@ __metadata: expo-constants: ~14.0.2 expo-linear-gradient: ~12.0.1 expo-linking: ~3.2.3 + expo-localization: ~14.0.0 expo-router: ^0.0.36 expo-status-bar: ~1.4.2 i18next: ^22.0.6 + intl-pluralrules: ^1.3.1 moti: ^0.21.0 react: 18.1.0 react-dom: 18.1.0 @@ -11527,6 +11547,13 @@ __metadata: languageName: node linkType: hard +"rtl-detect@npm:^1.0.2": + version: 1.0.4 + resolution: "rtl-detect@npm:1.0.4" + checksum: d562535baa0db62f57f0a1d4676297bff72fd6b94e88f0f0900d5c3e810ab512c5c4cadffd3e05fbe8d9c74310c919afa3ea8c1001c244e5555e8eef12d02d6f + languageName: node + linkType: hard + "run-parallel@npm:^1.1.9": version: 1.2.0 resolution: "run-parallel@npm:1.2.0"