Support for custom interpolation context
Closed this issue · 1 comments
Hi,
We've been working with angular-gettext in corporate-level application and it's been great for us, so to start with thanks!
At some point we have problems with translation messages that includes interpolation with some custom logic (like filters for example). It turned out that changing filters order or date format brokes translations. To give you an example:
<span translate>Last modified {{date | date:'yyyy-MM-dd HH:mm:ss Z'}} by {{user}}.</span>
When we extracted such a message we had to deal with various kind of problems:
- 3rd party translators tends to mess around with coping {{date | date:'yyyy-MM-dd HH:mm:ss Z'}} which results in wrong date display or missing date at all.
- Translators tends to ask unnecessary questions regarding some custom code within translations.
- When we decided to rename variables, filters order, date format, currency displays etc. it required to change translation files as well.
Simple solution would be to just separate translations like this:
<span><span translate>Last modified </span>{{date | date:'yyyy-MM-dd HH:mm:ss Z'}} <span translate>by</span> {{user}}.</span>
We tried that but it left us with no meaningful phrases to translate - like 'by'. Without context it's sometimes hard to translate, looks ugly and pain to refactor. So we came up with the solution that was great for us - allowing to pass some custom params to translate directive and leave simpler strings for translations. Example:
<span translate translate-params-date="date | date:'yyyy-MM-dd HH:mm:ss Z'">Last modified {{date}} by {{user}}.</span>
We tested that out and it seems legit. I've already prepared pull request with detailed description, unit tests and so on. I would love to see it merge. If you like it I'm also able to write additional docs.
Let me know what you think.
Cheers,
Ernest