[i18n] enable control over translation message ID
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 Currently the traduction ID is created by hashing the node content and the traduction “meaning” value. e.g: :
for this html fragment :
<p i18n="vehicule|personal vehicule">the car</p>
the traduction ID will be a hash of the car[vehicule]
Fixing any typo in the html tag content (in this example removing the two spaces between “the” and “car”) will create a new ID for translation. So I will have to change the ID for each XLIFF | XTB files despite the fact that I don’t know the ID because it’s a hash.
Expected behavior It would be very useful to have an option to disable the message ID generation to only use the “meaning” value as the translation ID.
For example, we can have an option in the ng-xi18n script to disable hashing :
./node_modules/.bin/ng-xi18n --i18nFormat=xlf --meaningAsId
And add a new provider in the app :
platformBrowserDynamic().bootstrapModule(AppModule, {[
{provide : TRANSLATIONS, useValue : translationFile},
{provide : TRANSLATIONS_FORMAT, useValue : 'xlf'},
{provide : LOCALE_ID, useValue : 'fr'},
{provide : MESSAGE_ID, useValue : 'meaning'}
]});
What is the motivation / use case for changing the behavior?
This feature will avoid the fact that each minimal changes in the “original content” (without affecting the meaning of a word or sentence) will produce a crash of the app because the message ID changes for the HTML_parser
. In other words, if the developper adds a meaning in the i18n attribute, he must have the choice to change the translation (by changing its ID) or not.
Currently, it’s impossible to change something in the original content without fixing the ID for every translation files.
-
Angular version: 2.1.0
-
Browser: all
-
Language: TypeScript 2.0.2
-
Node (for AoT issues):
node --version
= 4.4.1
Issue Analytics
- State:
- Created 7 years ago
- Reactions:8
- Comments:10 (6 by maintainers)
@vicb To detail and understand well your solution, you propose to add another parameter prefixed with @, so the parser will take it as translation ID.
Just to react a bit :
I agree that the purpose of the meaning is not to be a translation ID. But I don’t think it’s a good idea to use two different compilation strategies in a project (let angular generate IDs for some templates and give explicit IDs for others). It’s going to complicate development and maintainability. So I’m not against some global configurations.
Perhaps this global configuration can only check if each
i18n
attributes have an@id
and warn the developer if one missing somewhere.HOWEVER
I’m OK to have this kind of things in my templates :
The third example is important to be implemented. In my use case, I don’t always need a description or meaning (like for a close / save button).
If you’re OK with this, we can submit a pull request for this feature.
fixed via #13272