There are situations where a text can fit into several contexts.
{
"app_name": "Niro Health",
"text_1": "I'm Love $1",
}
locale.translate('text_1', '.app_name');
// output: I'm Love Niro Health
In the arguments you can pass properties as values. The passed properties can include '$' identifiers, making the nesting cascade mode.
{
"fallback": "Sorry the code is not working due to an error: $1",
"users": {
"get": {
"error": "$1"
}
},
}
locale.translate('users.get.error', '.fallback', 'Bad Line 404');
// output: Sorry the code is not working due to an error: Bad Line 404
You may need to pass a nested property that will not use cascade mode.
{
"fallback": "Sorry the code is not working due to an error: $1 and $2. Testing ? $3",
"users": {
"get": {
"error": "$1"
}
},
}
const values = [400, 500, true];
locale.translate('users.get.error', `.fallback.nocascade[${values.join(', ')}]`);
// output: Sorry the code is not working due to an error: 400 and 500. Testing ? true
Now you can structure texts even more dynamically, and best of all, your language file is even more organized and reduced.