Recursive Translation & Interpolation
See original GitHub issueI’m submitting a … (check one with “x”)
[ ] bug report => check the FAQ and search github for a similar issue or PR before submitting
[x] support request => check the FAQ and search github for a similar issue before submitting
[ ] feature request
Current behavior Support for parameters to be added/interpolated to another translated string is fine.
Expected/desired behavior The parameters which need to be added to the translated string might need to be translated themselves.
Reproduction of the problem I have various output on a form for errors. The field names are added into the output error string as a parameter:
en.json
{
"GENERAL": {
"ERROR": "The {field} field has an error"
},
"FIELDS":{
"FIRSTNAME": "First Name"
}
}
component.html
<p *ngIf="errors" translate [translateParams]="{field: labels[key]}">
GENERAL.ERROR
</p>
What is the expected behavior? The ‘field’ parameter should be catered for translation too, as for now, the field names would only be in English.
What is the motivation / use case for changing the behavior? By allowing the key for another field to be translated too, a more dynamic translation implementation could be achieved.
Is it possible to achieve something like this without referencing the TranslateService in a components class to translate the labels prior to adding them as parameters for another string to be translated in the components template?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:5
Top GitHub Comments
Currently not - sorry. It would require creating a quite complex way of handling the strings. Especially if user input contains {} and triggers other unwanted replacements…
@CodeAndWeb ok cool thanks man, was just wanting to know why 😛 does make sense though