I'm not sure how your translation is organized exactly but I had similar situation with constants translation and I found solution that suited me. If you have translation file with key - value translation format you can use it.
So you have constants file like this:
export default [
{
id: 1,
label: 'Cat'
},
{
id: 2,
label: 'Dog'
}
]
And have translation for this values:
{
"Animal.title": {
"en-uk": "Animals",
"da-dk": "Dyr"
},
"Animal.cat": {
"en-uk": "Cat",
"da-dk": "Kat"
},
"Animal.dog": {
"en-uk": "Dog",
"da-dk": "Hund"
}
}
And you have HOC that provides you translate
method and MyComponent that you need to translate (not sure how it's implemented in your app but I imagine it like this).
import Animals from './constants/animals'
class MyComponent extends React.Component {
render() {
const { translate } = this.props
return (
<div>
{translate('Animal.title')}
{Animals.map(animal => (
<Animal
id={animal.id}
name={animal.label}
/>
)}
</div>
)
}
}
translate('MyComponent')(MyComponent);
So now we have translated MyComponent but there is a problem - constants from pure js file are not translated. In this case I see only one solution - rewrite constants in this way:
export default [
{
id: 1,
label: 'Animal.cat'
},
{
id: 2,
label: 'Animal.dog'
}
]
We replaced labels with translation key, so now we can change out MyComponent to translate labels:
class MyComponent extends React.Component {
render() {
const { translate } = this.props
return (
<div>
{translate('Animal.title')}
{Animals.map(animal => (
<Animal
id={animal.id}
name={translate(animal.label)}
/>
)}
</div>
)
}
}