From 7103b9ffb1d458331713e997503583d4de44930d Mon Sep 17 00:00:00 2001 From: gnezim Date: Tue, 14 Apr 2026 23:21:25 +0300 Subject: [PATCH] Add I18nProvider with useTranslation re-export for feature code --- src/i18n/provider.tsx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/i18n/provider.tsx diff --git a/src/i18n/provider.tsx b/src/i18n/provider.tsx new file mode 100644 index 00000000..53efeb46 --- /dev/null +++ b/src/i18n/provider.tsx @@ -0,0 +1,36 @@ +import { + I18nextProvider, + useTranslation as useTranslationOriginal, +} from "react-i18next"; +import type { ReactNode } from "react"; +import type i18next from "i18next"; + +/** + * Wraps the i18next provider. All downstream code accesses translations + * through this provider and the re-exported hooks below. + */ +export function I18nProvider({ + i18n, + children, +}: { + i18n: typeof i18next; + children: ReactNode; +}): JSX.Element { + return {children}; +} + +/** + * Re-export of react-i18next's useTranslation. Feature code MUST import + * from "@/i18n/provider", never from "react-i18next" directly (enforced + * by the no-restricted-imports ESLint rule in 1A-3). + */ +export const useTranslation = useTranslationOriginal; + +/** + * Convenience alias for accessing the i18next instance from context. + * Same as useTranslation().i18n. + */ +export function useI18n(): typeof i18next { + const { i18n } = useTranslation(); + return i18n; +}