-
-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
There is a feature in react-i18next
(looks undocumented) that lets you hot swap the i18n instance using props:
import { useTranslation, Translation, Trans } from "react-i18next";
import i18nInstance from "./i18n";
function MyComponent() {
const { t } = useTranslation("ns", { i18n: i18nInstance });
return (
<>
<Trans i18n={i18nInstance} {...} />
<Translation i18n={i18nInstance} {...} />
</>
);
}
This is immensely helpful when working with internal packages, as each package can use its own i18n instance (and translation source) without conflicting with the top-level provider.
import { Component, Sync } from "my-package";
import i18n from "./i18n";
function MyApp() {
return (
<I18nProvider i18n={i18n}>
{/* Sync component is used to sync the language */}
{/* of the package with the application. */}
<Sync i18n={i18n} />
{/* Component uses its own i18n instance and */}
{/* translation source. */}
<Component />
</I18nProvider>
);
}
Can such feature be considered with Tolgee ?
import { useTranslate, T } from '@tolgee/react';
import tolgeeInstance from "./tolgee";
function MyComponent() {
const { t } = useTranslate("ns", { tolgee: tolgeeInstance });
return (
<>
<T tolgee={tolgeeInstance} {...} />
</>
);
}
Metadata
Metadata
Assignees
Labels
No labels