Variable names for sub translations
For example: you have a customer and want to show him a text with his name. Usually in every language it is some bit different:
In German:
{{gender == 'w' ? 'Frau' : 'Herr'}}{{title ? ' ' + title : ''}} {{firstName}} {{lastName}}
In English:
{{title ? title : (gender == 'w' ?'Mrs.' : 'Mr.')}} {{firstName}} {{lastName}}
In Bajoran:
{{lastName}} {{firstName}}
So it is for sure language dependent. And you have it not only once. You show a name here a name here and a name here. And everywhere the same logic. Ok to be honest it does not change every day. But If you have a mistake in the first time your wrote this expression and copy pasted it you need to search and replace or make another mistake... DRY: don't repeat yourself.
Ok you can have a name variable and give it to your translation:
{
"SALUTATION": "{{title ? title : (gender == 'w' ?'Mrs.' : 'Mr.')}} {{firstName}} {{lastName}}",
"WELCOME": "Welcome [[SALUTATION:gender,title,firstName,lastName]]",
"SUPPORT_INCOME": "The customer [[SALUTATION:gender,title,firstName,lastname]] has a quest."
}
Two drawbacks here: you can only copy variables with the same name and you can only copy the complete variable. Lets assume you have a customer with this data: {"gender":"w","firstName":"Jane","lastName":"Doe","and":"some","more":"data"}
. Currently the ways are not strait forward:
translateService.translate('SUPPORT_INCOME', {
'gender': customer.gender,
'title': customer.title,
'firstName': customer.firstName,
'lastName': customer.lastName,
'customer': customer
});
solution:
The customer [[SALUTATION:=customer]] has the question '{{title}}'
or The customer [[SALUTATION:gender=customer.gender,title=customer.title,firstName=customer.firstName,lastName=customer.lastName]]