Translations for sentences with form inputs that form part of the sentence? #935
-
I'm currently building a feature that I'm struggling to think of how to provide translations for. Consider the following sentence where [] are inputs that the user can manipulate, where the initial values might be: const energy = 'energy' "the cost of [energy] will rise by [percentage] over the next [months] months" How should I handle translations where the position of the inputs in the sentence will likely change depending on the language? We could break out 'the cost of', '*energy dropdown', 'will rise by" etc. But depending on the language, word order might be different, and I feel like doing it in that way would make for a really weird looking and hard to maintain messages json. Any suggestions / experiences / patterns to leverage from the community would be much appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If I understand your problem correctly, you can use interpolation of dynamic values. Then for each language you can set the placeholder for these values in different position in the sentence. const energy = t('energy')
const sentence = t('sentence', {energy}) |
Beta Was this translation helpful? Give feedback.
If I understand your problem correctly, you can use interpolation of dynamic values. Then for each language you can set the placeholder for these values in different position in the sentence.
Additionally, if you need the value itself to be translated, you can translate it before sending as a parameter in the interpolation. Example: