1
votes

In their examples on github, and in other places, react-i18next seem to suggest that we should use their Trans component by filling it with some kind of text, which to my understanding does not appear in the resulting app in any way since it gets overwritten by the default locale. What's it for? Is it just there to make sure react doesn't optimize away the components?

2
Can you elaborate more on what you mean? - adrai

2 Answers

2
votes

An old question, but this fantastic resource here really helped me wrap my head around the <Trans /> component.

0
votes

So after doing some more research, and trying a few suggestions, it seems that the recommended way to use <Trans> is to use the default text as a key in your autogenerated translation files, so

<Trans>Lorem ipsum</Trans>

in your code would give you

{"Lorem ipsum": "Lorem ipsum"}

in your default locale file, which could then be translated like

{"Lorem ipsum": "Löksås yxskaft"}