Add I18nProvider with useTranslation re-export for feature code

This commit is contained in:
2026-04-14 23:21:25 +03:00
parent a8c648c818
commit 7103b9ffb1
+36
View File
@@ -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 <I18nextProvider i18n={i18n}>{children}</I18nextProvider>;
}
/**
* 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;
}