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.

ng i18n --ivy does not extract correctly HTML message with interpolation

See original GitHub issue

🐞 Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

the ng i18ncommand extracts message correctly.

Description

I’m trying to use ng xi18n --ivy command with Angular 10.1.5 / CLI 10.1.5 packages to extract all my Typescript and HTML text for translation.

I have for example a label shared in four HTML templates. ng xi18n extract this label and add four location with the right interpolation.

ng xi18n --ivy generates a single location (false because it points on Typescript invalid code instead of HTML one) and interpolation is malformed. (single {instead of two {{ and ? misplaced).

πŸ”¬ Minimal Reproduction

For example, with this template code:

<mad-modal-confirm i18n="@@MAD.confirmDeleteModalMsg" i18n-title="@@psSetupPanel.modalConfirmTitle" title="Delete Power Supply" size="md" id="deletePowerSupplyButton" (closed)="deletePowerSupplyConfirm($event)">
  Confirm delete {{uiName}}?
</mad-modal-confirm>

The ng xi18n --output-path locale --format=xlf2 command will generate:

    <unit id="MAD.confirmDeleteModalMsg">
      <notes>
        <note category="location">app/components/setup/ps/setup-panel/ps-setup-panel.component.html:7,9</note>
        <note category="location">app/components/setup/wall/panel-setup/panel-setup.component.html:56,58</note>
        <note category="location">app/components/setup/vc/setup-panel/vc-setup-panel.component.html:10,12</note>
        <note category="location">app/components/setup/zone/detail/zone-detail.component.html:14,16</note>
      </notes>
      <segment>
        <source>
  Confirm delete <ph id="0" equiv="INTERPOLATION" disp="{{uiName}}"/>?
</source>
      </segment>
    </unit>

and the ng xi18n --ivy --output-path src/locale --format=xlf2 --out-file=messages-ivy.xlfcommand will generate:

    <unit id="MAD.confirmDeleteModalMsg">
      <notes>
        <note category="location">src/app/components/setup/zone/detail/zone-detail.component.ts:111</note>
      </notes>
      <segment>
        <source> Confirm delete <ph id="0" equiv="INTERPOLATION" disp="{uiName}}?"/>?
</source>
      </segment>
    </unit>

πŸ”₯ Exception or Error





🌍 Your Environment





     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / β–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 10.1.6
Node: 12.18.4
OS: darwin x64

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

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1001.6
@angular-devkit/build-angular   0.1001.6
@angular-devkit/core            10.1.6
@angular-devkit/schematics      10.1.6
@angular/cdk                    10.2.4
@angular/cli                    10.1.6
@schematics/angular             10.1.6
@schematics/update              0.1001.6
rxjs                            6.6.3
typescript                      4.0.3

Anything else relevant?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:23 (13 by maintainers)

github_iconTop GitHub Comments

2reactions
petebacondarwincommented, Oct 22, 2020

LOL! We had the same idea!

1reaction
bougnat12commented, Nov 18, 2020

I think you have to create a new build target first, with the new tsconfig. And then reference this new target in your browserTarget property of your extract-i18n target.

@petebacondarwin Thanks for your directions! it was a little bit heavy (in my head at least πŸ˜‰) but I succeeded.

Because we cannot use es2015 target for our production build it’s the best solution for us.

Best regards.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Newest 'angular-i18n' Questions - Stack Overflow
I'm trying to extract i18n messages from a complex angular using the following cli command: ng extract-i18n --out-file="src/locale/messages.xlf" --format=xlfΒ ...
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 >
Localizing your app - Angular Hispano
The ng xi18n extraction mechanism uses the ViewEngine compiler, which is not able to cope with some code syntax that the Ivy compiler...
Read more >
ng extract-i18n - Angular
Option Description Default Value ‑‑format Output format for the generated file. xlf ‑‑out‑file Name of the file to output. ‑‑output‑path Path where output will be placed....
Read more >
Angular internationalization (i18n) tutorial - Localizely
ng new angular-i18n-example Would you like to add Angular routing? No ... Now that we have successfully extracted the source language file,Β ...
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