From be54eb11fede0b07f39de80bcb2af6475da62098 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Fri, 14 Feb 2025 23:38:00 +0100 Subject: [PATCH] Auto switch between ssr and browser mode of translations --- front/src/providers/index.tsx | 6 +++++- front/src/providers/translations.ssr.tsx | 1 + front/src/providers/translations.tsx | 1 + front/tsconfig.json | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/front/src/providers/index.tsx b/front/src/providers/index.tsx index e3b675a1..2550dd72 100644 --- a/front/src/providers/index.tsx +++ b/front/src/providers/index.tsx @@ -6,7 +6,11 @@ import { ThemeSelector } from "~/primitives/theme"; import { createQueryClient } from "~/query"; import { AccountProvider } from "./account-provider"; import { ErrorConsumer, ErrorProvider } from "./error-provider"; -import { TranslationsProvider } from "./translations.ssr"; + +const { TranslationsProvider } = + typeof window === "undefined" + ? await import("./translations.ssr") + : await import("./translations"); const QueryProvider = ({ children }: { children: ReactNode }) => { const [queryClient] = useState(() => createQueryClient()); diff --git a/front/src/providers/translations.ssr.tsx b/front/src/providers/translations.ssr.tsx index 8b6b1606..084c9f52 100644 --- a/front/src/providers/translations.ssr.tsx +++ b/front/src/providers/translations.ssr.tsx @@ -12,6 +12,7 @@ export const supportedLanguages = readdirSync( export const TranslationsProvider = ({ children }: { children: ReactNode }) => { const val = useMemo(() => { const i18n = i18next.createInstance(); + // TODO: make a real language detector i18n.use(FsBackend).init({ interpolation: { escapeValue: false, diff --git a/front/src/providers/translations.tsx b/front/src/providers/translations.tsx index 19b5d748..88058d3b 100644 --- a/front/src/providers/translations.tsx +++ b/front/src/providers/translations.tsx @@ -7,6 +7,7 @@ import { I18nextProvider } from "react-i18next"; export const TranslationsProvider = ({ children }: { children: ReactNode }) => { const val = useMemo(() => { const i18n = i18next.createInstance(); + // TODO: use https://github.com/i18next/i18next-browser-languageDetector i18n.use(HttpApi).init({ interpolation: { escapeValue: false, diff --git a/front/tsconfig.json b/front/tsconfig.json index ebeffc69..50d81a2e 100644 --- a/front/tsconfig.json +++ b/front/tsconfig.json @@ -11,6 +11,7 @@ "noEmit": true, "module": "Preserve", "moduleResolution": "Bundler", + "target": "ES2017", "preserveSymlinks": true, "skipLibCheck": true, "jsx": "react-jsx",