Auto switch between ssr and browser mode of translations

This commit is contained in:
Zoe Roux 2025-02-14 23:38:00 +01:00
parent 31c183ecf1
commit be54eb11fe
No known key found for this signature in database
4 changed files with 8 additions and 1 deletions

View File

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

View File

@ -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<FsBackendOptions>({
interpolation: {
escapeValue: false,

View File

@ -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<HttpBackendOptions>({
interpolation: {
escapeValue: false,

View File

@ -11,6 +11,7 @@
"noEmit": true,
"module": "Preserve",
"moduleResolution": "Bundler",
"target": "ES2017",
"preserveSymlinks": true,
"skipLibCheck": true,
"jsx": "react-jsx",