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] enable control over translation message ID

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 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:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

8reactions
maxime-allexcommented, Nov 30, 2016

@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 :

‘meaningAsId’ seems restrictive in the sense that it applies globally

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 :

<p i18n="vehicule|personal vehicule@mypage.car">the car</p>
<p i18n="personal vehicule@mypage.car">the car</p>
<p i18n="@mypage.car">the car</p>

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.

1reaction
vicbcommented, Dec 16, 2016

fixed via #13272

Read more comments on GitHub >

github_iconTop Results From Across the Web

Migrating legacy localization IDs - Angular
The Angular translation system works by matching a message ID to a translated message in a different language. One option for creating these...
Read more >
Locale messages syntax | Vue I18n
In the above Locale Messages structure, You can translate using below key paths. <div id="app"> <!-- basic --> <p>{{ $t('key1') }}</p> <!
Read more >
Localizing your app - Angular Hispano
Import global variants of the locale data for extra locale data. Manage marked text with custom IDs if you require more control over...
Read more >
Genshi: Internationalization and Localization - PythonHosted.org
You can control automatic translation in your templates using the xml:lang attribute. ... The value of the i18n:msg attribute is a comma-separated list...
Read more >
angular i18n .xlf file ID's - confused when they change
Commit all translation message files to source control, especially the English source messages.xlf. The difference between the old and the new ...
Read more >

github_iconTop Related Medium Post

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