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 translation id for "String + Plural" expression

See original GitHub issue

I’m submitting an i18n feature request


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ ] Bug report  
[ ] Performance issue
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
[ ] Other... Please describe:

Current behavior

I am following the Angular 6 i18n guide: https://angular.io/guide/i18n Apparently there is no option to customize the id of the inner plural expression in an interpolated expression like “String + Plural

Example:

<span i18n="@@interpolated-time">Time: {minutes, plural, other {{{minutes}} elapsed}}</span>`

<trans-unit id="interpolated-time" datatype="html">
        <source>Time: <x id="ICU" equiv-text="{minutes, plural, other {...}}"/></source>
        <target>Tiempo: <x id="ICU" equiv-text="{minutes, plural, other {...}}"/></target>
</trans-unit>
<trans-unit id="plural-time" datatype="html">
        <source>{VAR_PLURAL, plural, other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> elapsed} }</source>
        <target>{VAR_PLURAL, plural, other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> transcurridos} }</target>
      </trans-unit>

The result is: Tiempo: 1440 elapsed

The workaround is to separate the expression in 2 simple expressions “string” + “plural”.

Expected behavior

  • The translation result should be Tiempo: 1440 transcurridos
  • Either, trans-unit should be detected automatically (by source) or the inner expression id should be customizable.

Minimal reproduction of the problem with instructions

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

  • Generating random translation id for inner expressions is not mantainable.
  • Managing inner expression ids is mantainable.

Environment


Angular version: 6


Browser:
- [ ] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
 
For Tooling issues:
- Node version: XX  
- Platform:  

Others:

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
andresoviedocommented, Oct 11, 2018

AFAIK, Angular splits “String + Plural” expression in 2 simpler expressions.

The plural inner expression gets a random identifier and it should match the trans-unit “id” in the messages.xlf file in order to work.

The exact Translate a nested expression example in https://angular.io/guide/i18n should be like this:

<trans-unit id="interpolated-time" datatype="html">
    <source>Updated: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></source>
    <target>Actualizado: <x id="ICU" equiv-text="{minutes, plural, =0 {...} =1 {...} other {...}}"/></target>
  </trans-unit>
  <trans-unit id="7151c2e67748b726f0864fc443861d45df21d706" datatype="html">
    <source>{VAR_PLURAL, plural, =0 {just now} =1 {one minute ago} other {<x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutes ago by {VAR_SELECT, select, male {male} female {female} other {other} }} }</source>
    <target>{VAR_PLURAL, plural, =0 {justo ahora} =1 {hace 1 minuto} other {hace <x id="INTERPOLATION" equiv-text="{{minutes}}"/> minutos por {VAR_SELECT, select, male {un hombre} female {una dama} other {otro} }} }</target>
  </trans-unit>

The id 7151c2e67748b726f0864fc443861d45df21d706 should be obtained from compilation output:

Missing translation for message "7151c2e67748b726f0864fc443861d45df21d706"

Is there any option to customize this random generated id in the expression?

0reactions
angular-automatic-lock-bot[bot]commented, Jul 24, 2022

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plurals - i18next documentation
We provide the ability to have special translation for {count: 0} , so that a more natural language can be used. If the...
Read more >
A Step-by-Step Guide to Go Internationalization (i18n)
Manually setting the translation strings ... The simplest way to organize the translations is to have them assigned into the application binary.
Read more >
Prepare component for translation - Angular
Use the i18n attribute to mark a static text message in your component templates for translation. Place it on every element tag that...
Read more >
Angular i18n: internationalization & localization with examples
trans-unit is the tag containing a single translation. id is a translation identifier and has a special meaning. xi18n generates the id for...
Read more >
Hugo Multilingual Part 2: Strings localization | Regis Philibert
i18n/en.yaml - id: hello translation: "Hello" - id: how_are_you ... sure this phrase is always faithfully localized, single or plural?
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