Internationalization of text that is formed by concatenating variables with constant strings

1k views Asked by At

Different languages structure sentences differently. In english we say White house, while other languages use a different structure where the noun is first, and the adjective second.

When I am creating a string I concatenate a color variable with a string constant using template literals.

`${color} House`

The adjective is alway before the noun.

If it was just a constant string White house the translation would be straight forward in the lang.json file. How do you accurately translate a string where it is composed of variables in a specific order; or in a set spot in the string, due to other languages structuring their sentences in a different order?

1

There are 1 answers

1
jamuhl On BEST ANSWER

Actually do not use template strings let the i18n framework do the job - most major i18n frameworks come with an interpolation feature, like eg. in i18next:

string resource myKey: {{color}} house -> i18next.t('myKey', { color: 'white' })

https://www.i18next.com/interpolation.html