Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom interpolation context #285

Closed
IShotTheSheriff opened this issue Jun 1, 2016 · 1 comment
Closed

Support for custom interpolation context #285

IShotTheSheriff opened this issue Jun 1, 2016 · 1 comment

Comments

@IShotTheSheriff
Copy link
Collaborator

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:

  1. 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.
  2. Translators tends to ask unnecessary questions regarding some custom code within translations.
  3. 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

@rubenv
Copy link
Owner

rubenv commented Jun 14, 2016

Closing this, let's continue the discussion on the pull request (#286).

Summary is that this makes so much sense that I'll make an exception to my "no new features"-rule. Love it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants