From 7adb1cd504d555f0224e47c4c58bc5a72ecbaeda Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Sun, 19 May 2024 16:33:50 +0200 Subject: [PATCH] Manually specify translations --- front/apps/mobile/app/_layout.tsx | 20 +++++++++----------- front/apps/mobile/package.json | 1 - front/apps/web/package.json | 4 +--- front/apps/web/src/i18n.tsx | 6 +++--- front/package.json | 5 +---- front/translations/index.js | 17 +++++++++++++++++ front/yarn.lock | 10 ---------- 7 files changed, 31 insertions(+), 32 deletions(-) create mode 100644 front/translations/index.js diff --git a/front/apps/mobile/app/_layout.tsx b/front/apps/mobile/app/_layout.tsx index 29e1062a..43e2e916 100644 --- a/front/apps/mobile/app/_layout.tsx +++ b/front/apps/mobile/app/_layout.tsx @@ -41,11 +41,11 @@ import { getLocales } from "expo-localization"; import { Slot } from "expo-router"; import * as SplashScreen from "expo-splash-screen"; import i18next from "i18next"; -import resourceToBackend from "i18next-resources-to-backend"; import "intl-pluralrules"; import { type ReactNode, useEffect, useState } from "react"; import { initReactI18next } from "react-i18next"; import { useColorScheme } from "react-native"; +import resources from "../../../translations"; import NetInfo from "@react-native-community/netinfo"; import { onlineManager } from "@tanstack/react-query"; @@ -72,16 +72,14 @@ const clientStorage = { export const clientPersister = createSyncStoragePersister({ storage: clientStorage }); -i18next - .use(initReactI18next) - .use(resourceToBackend((lang: string) => require(`../../../translations/${lang}.json`))) - .init({ - interpolation: { - escapeValue: false, - }, - fallbackLng: "en", - lng: getLocales()[0].languageCode ?? "en", - }); +i18next.use(initReactI18next).init({ + interpolation: { + escapeValue: false, + }, + fallbackLng: "en", + lng: getLocales()[0].languageCode ?? "en", + resources, +}); const NavigationThemeProvider = ({ children }: { children: ReactNode }) => { const theme = useTheme(); diff --git a/front/apps/mobile/package.json b/front/apps/mobile/package.json index 4095bab3..b00cdcbb 100644 --- a/front/apps/mobile/package.json +++ b/front/apps/mobile/package.json @@ -45,7 +45,6 @@ "expo-status-bar": "~1.12.1", "expo-updates": "~0.25.14", "i18next": "^23.11.4", - "i18next-resources-to-backend": "^1.2.1", "intl-pluralrules": "^2.0.1", "moti": "^0.29.0", "react": "18.2.0", diff --git a/front/apps/web/package.json b/front/apps/web/package.json index 0d0acae3..dab2c874 100644 --- a/front/apps/web/package.json +++ b/front/apps/web/package.json @@ -2,9 +2,7 @@ "name": "web", "version": "0.1.0", "private": true, - "sideEffects": [ - "./src/polyfill.ts" - ], + "sideEffects": ["./src/polyfill.ts"], "scripts": { "dev": "next dev", "build": "next build", diff --git a/front/apps/web/src/i18n.tsx b/front/apps/web/src/i18n.tsx index 56d529d9..60b87ac9 100644 --- a/front/apps/web/src/i18n.tsx +++ b/front/apps/web/src/i18n.tsx @@ -22,6 +22,7 @@ import i18next, { type InitOptions } from "i18next"; import type { AppContext, AppInitialProps, AppProps } from "next/app"; import { type ComponentType, useMemo } from "react"; import { I18nextProvider } from "react-i18next"; +import resources from "../../../translations"; export const withTranslations = ( AppToTranslate: ComponentType & { @@ -33,6 +34,7 @@ export const withTranslations = ( interpolation: { escapeValue: false, }, + resources, }; const AppWithTranslations = (props: AppProps) => { @@ -41,10 +43,9 @@ export const withTranslations = ( i18next.init({ ...commonOptions, lng: props.pageProps.__lang, - resources: props.pageProps.__resources, }); return i18next; - }, [props.pageProps.__lang, props.pageProps.__resources]); + }, [props.pageProps.__lang]); return ( @@ -61,7 +62,6 @@ export const withTranslations = ( fallbackLng: ctx.router.defaultLocale || "en", }); props.pageProps.__lang = lng; - // props.pageProps.__resources = resources; return props; }; diff --git a/front/package.json b/front/package.json index 4afa94d2..a132c7ae 100644 --- a/front/package.json +++ b/front/package.json @@ -14,10 +14,7 @@ "format": "biome format .", "format:fix": "biome format . --write" }, - "workspaces": [ - "apps/*", - "packages/*" - ], + "workspaces": ["apps/*", "packages/*"], "devDependencies": { "@biomejs/biome": "1.7.3", "typescript": "5.4.5" diff --git a/front/translations/index.js b/front/translations/index.js new file mode 100644 index 00000000..a20354ea --- /dev/null +++ b/front/translations/index.js @@ -0,0 +1,17 @@ +import de from "./de"; +import en from "./en"; +import fr from "./fr"; +import pl from "./pl"; +import tr from "./tr"; +import uk from "./uk"; +import zh from "./zh"; + +export default { + de: { translation: de }, + en: { translation: en }, + fr: { translation: fr }, + pl: { translation: pl }, + tr: { translation: tr }, + uk: { translation: uk }, + zh: { translation: zh }, +}; diff --git a/front/yarn.lock b/front/yarn.lock index 250c1e7c..d44bdd55 100644 --- a/front/yarn.lock +++ b/front/yarn.lock @@ -8822,15 +8822,6 @@ __metadata: languageName: node linkType: hard -"i18next-resources-to-backend@npm:^1.2.1": - version: 1.2.1 - resolution: "i18next-resources-to-backend@npm:1.2.1" - dependencies: - "@babel/runtime": ^7.23.2 - checksum: a2f338c4eec8d5ba09846ae1abdd23afb72086f6395d6160c748d010c82f5c28c30133f6487f0fd3a65e710231d7750b324785f15cac4baf6d24b33227840341 - languageName: node - linkType: hard - "i18next@npm:^23.11.4": version: 23.11.4 resolution: "i18next@npm:23.11.4" @@ -10471,7 +10462,6 @@ __metadata: expo-status-bar: ~1.12.1 expo-updates: ~0.25.14 i18next: ^23.11.4 - i18next-resources-to-backend: ^1.2.1 intl-pluralrules: ^2.0.1 moti: ^0.29.0 react: 18.2.0