Closed tuanlc closed 4 years ago
At first, we need to update the translation in order to make angular-translate understand things: https://ci.linagora.com/linagora/lgs/openpaas/esn/-/wikis/Frontend-Split/Stage-1/i18n
Suppose we have the following translation object:
{
"%s items": "{{ length }} items"
}
$translate.instant('%s items', { length })
should work.
In other words, esnI18nService.translate('%s items', $dragData.length);
needs to become esnI18nService.translate('%s items', { length: $dragData.length });
. Of course we'll have to modify the esnI18nService.translate
method accordingly.
And then we'll need to find every place where esnI18nService.translate
is used and modify it.
Edit: After that remember to remove the esnI18nInterpolator
factory as it is useless now.
Context:
To fix translation for templates, we updated translations to:
Address book %s will be deleted along with its contacts.: "Address book {{ addressbookDisplayShell.displayName }} will be deleted along with its contacts."
and we updated template to use:
p {{ 'Address book %s will be deleted along with its contacts.' | translate:$ctrl }}
To do this, we do not use i18nInterpolator that detects
%s
and replace them with proper values.Issue
Without
i18nInterpolator
, our syntax for exampleesnI18nService.translate('%s items', $dragData.length);
does not work because translator does not understand%s
anymore.We use this syntax in a ton of places in SPAs.
Solution
Consistent the input of esnI18nService.translate and angular translate filter, the second param (if present) is an object that contains pairs of key + value