Translation outside React Component
See original GitHub issueI tried to translate strings exported outside React Components. But any methods in docs doesn’t work, and I guess its normal, because its typically React methods.
I’ve found similar topic, and there it is solution about importing instance. But, when I do it I’ve had an error:
Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
Probably it because of this line in the instance:
i18n
.use(initReactI18next)
When I delete this line, the error is gone, but the translations are not included. How can I plug this simple .js file to React translations?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:26 (11 by maintainers)
Top Results From Across the Web
i18next translation outside component - Stack Overflow
Show activity on this post. I'm new for i18next, trying to localize/translate website. Everything works for translation inside of component, ...
Read more >Step by step guide - react-i18next documentation
The Trans component is the best way to translate a JSX tree in one translation. This enables you to eg. easily translate text...
Read more >Common i18n patterns in React — LinguiJS documentation
Translations outside React components ¶ · Create your own instance of i18n using setupI18n() form @lingui/core · Pass this instance as i18n prop...
Read more >How to use Translation outside a React component?
Hi, I'm trying to add translation to a object that is outside a React Component, is this possible?
Read more >Common i18n patterns in React — LinguiJS documentation
Using jsx macros is the most straightforward way how to translate your React components. <Trans> handles translations of messages including variables and other ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
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
Outside of react components just use the i18next instance:
Just be aware of the normal catch you’s:
i18n.t
returns a string — right?export default { foo: 'bar' }
— exports an object with a string foo — right?export default { foo: i18n.t('foo') }
— still exports an object with a string foo — right?how does a string magically changes? - it does not — right?
So this might work?