Hello guys i have a question for you. Actually i want to map and render a component using text from a .json and using translation based on user language or detected language.
That's the translation.json (the same for another language)
{ "myText":[
{ "id":1,
"text":"my text"
},
{
"id":2,
"text":"my text"
}
]
}
Now i want to map this .json and return the text based on language in my component. If i do:
import { withNamespaces } from 'react-i18next';
import data from '../locales/en/translation.json';
function Component({t}) {
return (
<>
{data.myText.map((item) => (
<div key={t(item.id)}>
{t(item.text)}
<div/>
))}
</>
)
}
export default withNamespaces()(Component)
That's return only the "en" translation because the import is based on this .json file. Now how to have the translation based on user language through .map ?