Skip to content

Commit

Permalink
fix: i18nProvider condition
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <[email protected]>
  • Loading branch information
Innei committed Sep 11, 2024
1 parent 53c1c66 commit 0f654b9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/renderer/src/providers/i18n-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ import type { FC, PropsWithChildren } from "react"
import { useEffect, useState } from "react"
import { I18nextProvider } from "react-i18next"

export const I18nProvider: FC<PropsWithChildren> = ({ children }) => {
const [currentI18NInstance, update] = useState(i18next)
if (import.meta.env.DEV)
// eslint-disable-next-line react-compiler/react-compiler, react-hooks/rules-of-hooks
let I18nProvider: FC<PropsWithChildren>

if (import.meta.env.DEV) {
I18nProvider = ({ children }) => {
const [currentI18NInstance, update] = useState(i18next)

useEffect(
() =>
EventBus.subscribe("I18N_UPDATE", () => {
update(i18next.cloneInstance())
}),
[],
)
return <I18nextProvider i18n={currentI18NInstance}>{children}</I18nextProvider>
return <I18nextProvider i18n={currentI18NInstance}>{children}</I18nextProvider>
}
} else {
I18nProvider = ({ children }) => <I18nextProvider i18n={i18next}>{children}</I18nextProvider>
}

export { I18nProvider }

0 comments on commit 0f654b9

Please sign in to comment.