Skip to content

Commit

Permalink
Fixes language detection
Browse files Browse the repository at this point in the history
The language detection now only allows for supported languages. Also,
the default language is "dev" only for development - it becomes "en" for
production.
  • Loading branch information
jacomyal committed Jul 13, 2023
1 parent eeff684 commit 9fd8ee2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/locales/LOCALES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export const LOCALES = {
label: "Français",
},
};

export const DEFAULT_LOCALE = process.env.NODE_ENV !== "production" ? "dev" : "en";
5 changes: 3 additions & 2 deletions src/locales/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import { initReactI18next, I18nextProvider } from "react-i18next";
import LngDetector from "i18next-browser-languagedetector";

import { usePreferences } from "../core/context/dataContexts";
import { LOCALES } from "./LOCALES";
import { DEFAULT_LOCALE, LOCALES } from "./LOCALES";

const i18n = i18next.use(initReactI18next).use(LngDetector);

i18n
.init({
debug: process.env.NODE_ENV !== "production",
fallbackLng: "dev",
fallbackLng: DEFAULT_LOCALE,
resources: LOCALES,
detection: {
order: ["querystring", "navigator"],
lookupQuerystring: "lang",
convertDetectedLanguage: (lng) => lng in LOCALES ? lng : DEFAULT_LOCALE,
},
})
.then(() => {
Expand Down

0 comments on commit 9fd8ee2

Please sign in to comment.