i18n: support variables as translation key
See original GitHub issueI’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:
- Created 7 years ago
- Reactions:17
- Comments:19 (9 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s blocked until some big changes to the compiler are done, so yes still a few months to wait unfortunately
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: