question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

i18n: support variables as translation key

See original GitHub issue

I’m submitting a … (check one with “x”)

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

I currently can’t find a way to use variable values as translation keys. I’m basically trying to do something like this:

        <select id="state" name="state" [(ngModel)]="task.state" class="form-control">
                <option *ngFor="let state of states" [value]="state" i18n>
                   {{state}}
                </option>
        </select>

where states is something like

states = ['BACKLOG', 'IN_PROGRESS', 'COMPLETED']

Expected behavior

It needs to be possible to use calculated values / variables as keys for translation

Reproduction of the problem

What is the motivation / use case for changing the behavior?

To be able to dynamically translate strings

  • Angular version: 2.0.1

  • Browser: [all ]

  • Language: [all]

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:17
  • Comments:19 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
ocombecommented, Apr 13, 2017

It’s blocked until some big changes to the compiler are done, so yes still a few months to wait unfortunately

2reactions
ocombecommented, Mar 13, 2017

Yes that’s no possible with dynamic variables right now. Once we can use i18n in TS code, you could easily fix your use case, the template would be the same (just remove i18n) and the code would be something like:

states = [this.i18n.__('BACKLOG'), this.i18n.__('IN_PROGRESS'), this.i18n.__('COMPLETED')]
Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Pass a Variable to Your Translation String With i18next
Let's learn how i18next interpolation works and how you can use this feature to pass one or more dynamic values to your translation...
Read more >
i18next - features
i18next will translate the key as usual. Then it passes the translation text to the post processor. Hint: Alternatively you can set i18next...
Read more >
Interpolation - i18next documentation
Interpolation is one of the most used functionalities in I18N. It allows integrating dynamic values into your translations.
Read more >
dynamic translation/translation with variable with i18next
using a variable with i18next? For example in my JS-file I got this: Here I use a variable and assign it to the...
Read more >
typesafe-i18n - npm
Parsing your translation file for variables and formatters will only be performed when you access a translation for the first time. The result...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found