Using i18next in enums (TypeScript)
See original GitHub issueHello, I’m using React with react-i18next plugin and I want to translate value of enums. Is it possible?
Code:
enum catSize {
SMALL = 'Small',
MEDIUM = 'Medium',
LARGE = 'Large',
}
and I’d like to convert this to something like:
enum catSize {
SMALL = t('sizes.small'),
MEDIUM = t('sizes.medium'),
LARGE = t('sizes.large'),
}
but obviously it won’t work because we don’t have access to t function which is provided by HOC. Is there any trick to achive translations outside render function and use it in my case?
Issue Analytics
- State:
- Created 5 years ago
- Comments:17 (6 by maintainers)
Top Results From Across the Web
TypeScript: is there a way to parameterize an enum
Now obviously it won't work with react-i18next . I wonder is there a way to parameterize the enum's value using Generics so we...
Read more >TypeScript - react-i18next documentation
TypeScript definitions for react-i18next can be extended by using Type Augmentation and Merging Interfaces. So the first step is creating a declaration file ......
Read more >enum-i18n - npm
Enum with support for translated member descriptions. ... Start using enum-i18n in your project by running `npm i enum-i18n`.
Read more >Angular i18n: Translate Enums | by Piotr Lewandowski
5 practices translating enums in Angular with built-in i18n.
Read more >Angular: Translate Enums (i18n) - Medium
Angular: Translate Enums (i18n) ... One of the biggest flaw of built-in Angular translation engine is it only supports translations known during ...
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
beside that…why does the enum need translated values at all? just move the translation to the rendering
in that case you can also just use i18n.t directly if you prefer…https://react.i18next.com/#what-is-react-i-18-next see first hint