Interpolation allows dynamic values to be used within translations. Interpolation
It is used where a value is uncertain, dynamic or susceptible to change.
It is also used with pluralisation.
How to use interpolation
In the JSON file, we use {{ }}
brackets to indicate where we will be using interpolation. This value will change depending on our provided value in the translation hook.
...
The code will now appear as:
Code Block | ||
---|---|---|
| ||
"I have a pet cat" |
...
Use interpolation sparingly
Interpolation should be used as little as possible. It cannot be avoided in cases of:
Time stamps
User-inputted data
Interpolation can cause issues when concatenating values. Depending on the interpolated value, the rest of the sentence may need to be changed , this can be seen here in the documentation. Interpolation should be used as little as possible. It can not be avoided in cases of:
Time stamps
User-inputted data
More about the implications and best practices of interpolation can be seen here.
zero, single or plural values are natively understood by i18n to parse zero, single or plural values and present different sentences depending on the value.