Skip to content

Commit

Permalink
feat: add locale auto-detect from navigator and user session
Browse files Browse the repository at this point in the history
  • Loading branch information
frkam committed Jun 21, 2023
1 parent 628317f commit 4c44675
Show file tree
Hide file tree
Showing 12 changed files with 224 additions and 463 deletions.
12 changes: 6 additions & 6 deletions .linguirc.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
locales:
- "en"
- "ru"
- "EN"
- "RU"

catalogs:
- path: ./src/shared/config/i18n/locales/{locale}
include:
- src
- path: ./src/shared/config/i18n/locales/{locale}
include:
- src

format: po
format: po
303 changes: 0 additions & 303 deletions public/mockServiceWorker.js

This file was deleted.

22 changes: 21 additions & 1 deletion src/app/main.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import { createEffect, sample } from "effector";
import { combineEvents } from "patronum";
import { createRoot } from "react-dom/client";

import { getSessionQuery } from "@/entities/session";

import { loadLocaleFx } from "@/shared/config/i18n/load-locale";
import { appStarted } from "@/shared/config/init";

import App from "./application";

const root = createRoot(document.querySelector("#root") as HTMLElement);

appStarted();
root.render(<App />);

const appDataLoaded = combineEvents({
events: {
loadLocale: loadLocaleFx.finally,
loadSession: getSessionQuery.finished.finally,
},
});

const renderAppFx = createEffect(() => {
root.render(<App />);
});

sample({
clock: appDataLoaded,
target: renderAppFx,
});
5 changes: 0 additions & 5 deletions src/app/providers/with-localization.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@ import { i18n } from "@lingui/core";
import { I18nProvider } from "@lingui/react";
import { type ComponentType } from "react";

import { DEFAULT_LANGUAGE } from "@/shared/config/i18n/languages";
import { loadLocale } from "@/shared/config/i18n/load-locale";

loadLocale(DEFAULT_LANGUAGE);

export const withLocalization = (WrappedComponent: ComponentType) => () => {
return (
<I18nProvider i18n={i18n}>
Expand Down
Loading

0 comments on commit 4c44675

Please sign in to comment.