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.

Angular i18n generates one trans-unit where two are needed.

See original GitHub issue

🐞 bug report

Affected Package

@angular/core

Is this a regression?

Never worked.

Description

When using icu for pluralisation the context of the words get lost. Some translations for the same words differ based on context.

🔬 Minimal Reproduction

What you first need to know:

German / English Person / person Personen / persons

Use in your project:

<p i18n>{items.length, plural, one {Person} other {Personen}} gehen unwiderruflich verloren.</p>

And somewhere else:

<p i18n>Entferne {items.length, plural, one {Person} other {Personen}}</p>

Note that the first letter of the noun is uppercase in german. No matter if it’s the beginning of a sentence or not.

Generate translation files and translate them. You will get three nodes. Something linke this:

        <source><x id="ICU" equiv-text="{items.length, plural, one {...} other {...}}"/> gehen unwiderruflich verloren.</source>
        <target><x id="ICU" equiv-text="{items.length, plural, one {...} other {...}}"/> will be lost permanently.</target>
        <source>Entferne <x id="ICU" equiv-text="{items.length, plural, one {...} other {...}}"/></source>
        <target>Remove <x id="ICU" equiv-text="{items.length, plural, one {...} other {...}}"/></target>
        <source>{VAR_PLURAL, plural, one {Person} other {Person} }</source>
        <target>{VAR_PLURAL, plural, one { ❓❓❓ } other { ❓❓❓ } }</target>

Problem: First sentence would need the translation {VAR_PLURAL, plural, one {Person} other {Persons} }

Second sentence would need the translation {VAR_PLURAL, plural, one {person} other {persons} }

I expected two trans-units. Something like this:

        <source>{items.length, plural, one {Person} other {Personen}} gehen unwiderruflich verloren.</source>
        <target>{items.length, plural, one {Person} other {Persons}} will be lost permanently.</target>

and

        <source>Entferne {items.length, plural, one {Person} other {Personen}}</source>
        <target>Remove {items.length, plural, one {Person} other {Persons}}</target>

🌍 Your Environment

Angular Version:


Angular CLI: 9.1.12
Node: 10.16.0
OS: darwin x64

Angular: 9.1.12
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, platform-server, router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.9
@angular-devkit/build-angular     0.901.9
@angular-devkit/build-optimizer   0.901.9
@angular-devkit/build-webpack     0.901.9
@angular-devkit/core              9.1.9
@angular-devkit/schematics        9.1.12
@angular/fire                     5.2.3
@ngtools/webpack                  9.1.9
@schematics/angular               9.1.12
@schematics/update                0.901.12
rxjs                              6.6.3
typescript                        3.8.3
webpack                           4.43.0

Anything else relevant? @ocombe announced that the ivy release will fix this. But people decided to not ship this in order to to make Ivy more backwards compatible.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
aprat84commented, Mar 10, 2022

This really prevents us to use ICU plural/select, as it separates ICU blocks into its own unique trans-unit across all translation strings.

This makes translation inaccurate for some reasons:

  • if a partial is used in more than one trans-unit, you don’t know the context
  • it’s not useful for translators to have a string divided in N+1 trans-unit (N = number of ICU blocks in string)

Saw at linked issue https://github.com/angular/angular/issues/25858 that a fix was announced for Ivy, but seems it was really never released.

What’s the state of this? @ocombe @AndrewKushnir @petebacondarwin

1reaction
lionel-meuniercommented, Nov 16, 2021

I have the same problem with the term “transactions” which has 2 translations in German for only one in English

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Internationalization
Internationalization, sometimes referenced as i18n, is the process of designing and preparing your project for use in different locales around the world.
Read more >
Angular: How to generate one trans-unit from i18n attribute ...
Yes, because you have two separate translations that each get a ... If you want to have only one trans unit you need...
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 >
How To Use Internationalization (i18n) in Angular | DigitalOcean
You can use @angular/cli to create a new Angular Project. ... needs translating (i.e., has the i18n directive), a trans-unit will be created ......
Read more >
The Ultimate Guide to Angular Localization | Phrase
Learn end-to-end Angular localization with the built-in i18n library ... We need to include the path to a translation file for each locale ......
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