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.

ICU expression (plural) does not work with angular and HTML tags, since angular 9

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/localize ?

Is this a regression?

Yes, the previous version in which this bug was not present was: 8.3.29

Description

After update to Angular 9 (and similarly for Angular 10), ICU expression does not render component or HTML tags inside ICU expression (in this case - plural expression). There is no error in browser or console, only "One " and "Other " strings are displayed without buttons (included in expressions). It worked fine for Angular 8 (both buttons were displayed):
<ng-container i18n="Plurals example">{
  pluralsValue, plural,
    one {One <ng-container *ngTemplateOutlet="myTemplate"></ng-container>}
    other {Other <button>button_other</button>}
}</ng-container>

<ng-template #myTemplate>
  <button>button_one</button>
</ng-template>

πŸ”¬ Minimal Reproduction

Angular 8 (working):

https://stackblitz.com/edit/angular-plurals-angular8 Angular 9 (not working, regression): https://stackblitz.com/edit/angular-plurals-angular9

πŸ”₯ Exception or Error





🌍 Your Environment

Angular Version:

Angular 9+



Anything else relevant?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
petebacondarwincommented, Aug 28, 2020

The new ivy extraction ought to be able to provide a bit better information about the original context of the placeholders, although currently I see it is rather broken:

<x id="START_TAG_NG_TEMPLATE" equiv-text="iner&gt; &lt;/ng-templ"/>
  One
  <x id="START_TAG_NG_CONTAINER" equiv-text="se=&quot;other&quot;&gt;Other &lt;button&gt;button_ot"/>
  <x id="CLOSE_TAG_NG_CONTAINER" equiv-text="&lt;/ng-container&gt;&lt;ng-template #myTem"/>
<x id="CLOSE_TAG_NG_TEMPLATE"/>
<x id="START_TAG_NG_TEMPLATE_1"/>
  Other
  <x id="START_TAG_BUTTON"/>button_other<x id="CLOSE_TAG_BUTTON"/>
<x id="CLOSE_TAG_NG_TEMPLATE"/>

I would expect it to be more like:

<x id="START_TAG_NG_TEMPLATE" equiv-text="&lt;ng-template ngPluralCase=&quot;one&quot;&gt;"/>
  One
  <x id="START_TAG_NG_CONTAINER" equiv-text="&lt;ng-container *ngTemplateOutlet=&quot;myTemplate&quot;&gt;"/>
  <x id="CLOSE_TAG_NG_CONTAINER" equiv-text="&lt;/ng-container&gt;"/>
<x id="CLOSE_TAG_NG_TEMPLATE" equiv-text="&lt;/ng-template&gt;/>
<x id="START_TAG_NG_TEMPLATE_1" equiv-text="&lt;ng-template ngPluralCase=&quot;other&quot&gt;"/>
  Other
  <x id="START_TAG_BUTTON" equiv-text="&lt;button&gt;"/>button_other<x id="CLOSE_TAG_BUTTON" equiv-text="&lt;/button&gt;"/>
<x id="CLOSE_TAG_NG_TEMPLATE" equiv-text="&lt;/ng-template&gt;/>

I will work on some fixes for this…

1reaction
petebacondarwincommented, Aug 26, 2020

@rygoebel thanks for the excellent reproductions of this problem. I can confirm that this is a regression. @mhevery is currently reworking some of the ICU handling in Ivy and so this may be related.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use angular 9 $localize with plurals? - Stack Overflow
For now, it is not possible to use ICUs with $localize , as discussed in this github issue. From the last comments, it...
Read more >
Prepare component for translation - Angular
The attributes of HTML elements include text that should be translated along ... Use the plural clause to mark expressions that may not...
Read more >
The Ultimate Guide to Angular Localization | Phrase
How do I work with plurals in my translations? Angular implements the ICU standard for its localized plurals. ICU is a bit outside...
Read more >
Angular i18n: internationalization & localization with examples
Working with Angular pipes. Performing translations within components. Adding a language switcher. Building the app and deploying to production.
Read more >
Angular Translation: A Closer Look at Angular 8 - Medium
This tutorial will guide you through the process of Angular translation in the framework's latest, eighth version by using the built-in I18n module....
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