Manually specify translations

This commit is contained in:
Zoe Roux 2024-05-19 16:33:50 +02:00
parent ec60dccb7b
commit 7adb1cd504
No known key found for this signature in database
7 changed files with 31 additions and 32 deletions

View File

@ -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();

View File

@ -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",

View File

@ -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",

View File

@ -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<AppProps> & {
@ -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 (
<I18nextProvider i18n={li18n}>
@ -61,7 +62,6 @@ export const withTranslations = (
fallbackLng: ctx.router.defaultLocale || "en",
});
props.pageProps.__lang = lng;
// props.pageProps.__resources = resources;
return props;
};

View File

@ -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"

View File

@ -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 },
};

View File

@ -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