Use I18nextProvider with a components library
See original GitHub issueQuestion about react-i18next
Hello,
I have a question about the utilization of I18nextProvider.
Here is my code :
i18next
.use(initReactI18next)
.init({
resources: {
en: {
translation: {
"Validate": "Validate"
},
},
fr: {
translation: {
"Validate": "Valider"
}
},
lng: "fr",
fallbackLng: "fr",
interpolation: {
escapeValue: false
}
}
});
i18next.changeLanguage('fr')
class App extends Component {
render() {
return (
<I18nextProvider i18n={i18next}>
<Toto/>
</I18nextProvider>
);
}
}
export default App;
And my component Toto is :
class Toto extends Component {
render() {
const { t } = this.props;
return (
<p>{t('Validate')}</p>
)
}
}
const translatedToto = withTranslation()(Toto);
export { translatedToto as Toto };
If my Toto is in the same project that my component App it works well. But if my Toto component is in an external package, the translation doesn’t works and I have the following message in the console :
react-i18next:: You will need pass in an i18next instance by using i18nextReactModule
I am currently developing a components library so I use npm link to make the link between my components library and my test project.
So my question is the following : There is a particular way to use I18nextProvider in this specific case ? Generally, what is the best practice to use react-i18next with a components library ?
Thanks.
Damien
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:20 (8 by maintainers)
Top Results From Across the Web
I18nextProvider - react-i18next documentation
The I18nextProvider does take an i18next instance via prop i18n and ... multiple i18next instances - eg. if you provide a component library...
Read more >Use parent i18next with a React components library
I have a mono repo with an app and a components library called ui . ... Inject the i18next via the I18nextProvider and...
Read more >How to have multiple instances of i18next for component library
Step 1: create i18next instance. In component library, we will need to create an i18next instance, and not use initReactI18next to initialize it ......
Read more >A Guide to React Localization with i18next | Phrase
React-i18next is a powerful set of components, hooks, and plugins that sit on top of i18next. Learn how to use it to internationalize...
Read more >How to translate your React app with react-i18next
As we want to use react-i18next to localize our application, add it to you ... all our components we have to wrap the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You can use
<I18nextProvider />
to reference the same instance.Here is my solution to refactoring the i18nInstance to a separate library (for a lerna monorepo for example)
you can transpile them…but exclude react from being included…there at anytime should be only one react instance…that’s all