Skip to content

Commit

Permalink
feat: add i18n detector
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 12, 2024
1 parent 6ed0a3b commit 7eb8a32
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"hast-util-to-jsx-runtime": "2.3.0",
"hast-util-to-text": "4.0.2",
"i18next": "^23.15.1",
"i18next-browser-languagedetector": "8.0.0",
"idb-keyval": "6.2.1",
"immer": "10.1.1",
"jotai": "2.9.3",
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 12 additions & 7 deletions src/renderer/src/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventBus } from "@renderer/lib/event-bus"
import dayjs from "dayjs"
import i18next from "i18next"
import LanguageDetector from "i18next-browser-languagedetector"
import { atom } from "jotai"
import { initReactI18next } from "react-i18next"

Expand All @@ -14,13 +15,17 @@ export const defaultNS = "app"
export const fallbackLanguage = "en"
export const initI18n = async () => {
const i18next = jotaiStore.get(i18nAtom)
await i18next.use(initReactI18next).init({
lng: "en",
fallbackLng: fallbackLanguage,
defaultNS,
debug: import.meta.env.DEV,
resources: defaultResources,
})
await i18next
.use(initReactI18next)
.use(LanguageDetector)
.init({
lng: "en",

fallbackLng: fallbackLanguage,
defaultNS,
debug: import.meta.env.DEV,
resources: defaultResources,
})

dayjs.locale("en")
}
Expand Down

0 comments on commit 7eb8a32

Please sign in to comment.