Skip to content

Support for custom interpolation context #285

Description

@IShotTheSheriff

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions