|
1 | | -import { RemixBrowser } from "@remix-run/react"; |
2 | | -import { startTransition, StrictMode } from "react"; |
3 | | -import { hydrateRoot } from "react-dom/client"; |
4 | | -import i18n from "~/localization/i18n"; |
5 | | -import i18next from "i18next"; |
6 | | -import { I18nextProvider, initReactI18next } from "react-i18next"; |
7 | | -import LanguageDetector from "i18next-browser-languagedetector"; |
8 | | -import Backend from "i18next-http-backend"; |
9 | | -import { getInitialNamespaces } from "remix-i18next/client"; |
10 | | -import { resources } from "./localization/resource"; |
| 1 | +import { RemixBrowser } from "@remix-run/react" |
| 2 | +import i18next from "i18next" |
| 3 | +import LanguageDetector from "i18next-browser-languagedetector" |
| 4 | +import Backend from "i18next-http-backend" |
| 5 | +import { StrictMode, startTransition } from "react" |
| 6 | +import { hydrateRoot } from "react-dom/client" |
| 7 | +import { I18nextProvider, initReactI18next } from "react-i18next" |
| 8 | +import { getInitialNamespaces } from "remix-i18next/client" |
| 9 | +import i18n from "~/localization/i18n" |
| 10 | +import { resources } from "./localization/resource" |
11 | 11 |
|
12 | 12 | async function hydrate() { |
13 | | - // eslint-disable-next-line import/no-named-as-default-member |
14 | | - await i18next |
15 | | - .use(initReactI18next) // Tell i18next to use the react-i18next plugin |
16 | | - .use(LanguageDetector) // Setup a client-side language detector |
17 | | - .use(Backend) // Setup your backend |
18 | | - .init({ |
19 | | - ...i18n, // spread the configuration |
20 | | - // This function detects the namespaces your routes rendered while SSR use |
21 | | - ns: getInitialNamespaces(), |
22 | | - backend: { loadPath: "/locales/{{lng}}/{{ns}}.json" }, |
23 | | - resources, |
24 | | - detection: { |
25 | | - // Here only enable htmlTag detection, we'll detect the language only |
26 | | - // server-side with remix-i18next, by using the `<html lang>` attribute |
27 | | - // we can communicate to the client the language detected server-side |
28 | | - order: ["htmlTag"], |
29 | | - // Because we only use htmlTag, there's no reason to cache the language |
30 | | - // on the browser, so we disable it |
31 | | - caches: [], |
32 | | - }, |
33 | | - }); |
| 13 | + // eslint-disable-next-line import/no-named-as-default-member |
| 14 | + await i18next |
| 15 | + .use(initReactI18next) // Tell i18next to use the react-i18next plugin |
| 16 | + .use(LanguageDetector) // Setup a client-side language detector |
| 17 | + .use(Backend) // Setup your backend |
| 18 | + .init({ |
| 19 | + ...i18n, // spread the configuration |
| 20 | + // This function detects the namespaces your routes rendered while SSR use |
| 21 | + ns: getInitialNamespaces(), |
| 22 | + backend: { loadPath: "/locales/{{lng}}/{{ns}}.json" }, |
| 23 | + resources, |
| 24 | + detection: { |
| 25 | + // Here only enable htmlTag detection, we'll detect the language only |
| 26 | + // server-side with remix-i18next, by using the `<html lang>` attribute |
| 27 | + // we can communicate to the client the language detected server-side |
| 28 | + order: ["htmlTag"], |
| 29 | + // Because we only use htmlTag, there's no reason to cache the language |
| 30 | + // on the browser, so we disable it |
| 31 | + caches: [], |
| 32 | + }, |
| 33 | + }) |
34 | 34 |
|
35 | | - startTransition(() => { |
36 | | - hydrateRoot( |
37 | | - document, |
38 | | - <I18nextProvider i18n={i18next}> |
39 | | - <StrictMode> |
40 | | - <RemixBrowser /> |
41 | | - </StrictMode> |
42 | | - </I18nextProvider> |
43 | | - ); |
44 | | - }); |
| 35 | + startTransition(() => { |
| 36 | + hydrateRoot( |
| 37 | + document, |
| 38 | + <I18nextProvider i18n={i18next}> |
| 39 | + <StrictMode> |
| 40 | + <RemixBrowser /> |
| 41 | + </StrictMode> |
| 42 | + </I18nextProvider> |
| 43 | + ) |
| 44 | + }) |
45 | 45 | } |
46 | 46 |
|
47 | 47 | if (window.requestIdleCallback) { |
48 | | - window.requestIdleCallback(hydrate); |
| 48 | + window.requestIdleCallback(hydrate) |
49 | 49 | } else { |
50 | | - // Safari doesn't support requestIdleCallback |
51 | | - // https://caniuse.com/requestidlecallback |
52 | | - window.setTimeout(hydrate, 1); |
| 50 | + // Safari doesn't support requestIdleCallback |
| 51 | + // https://caniuse.com/requestidlecallback |
| 52 | + window.setTimeout(hydrate, 1) |
53 | 53 | } |
0 commit comments