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.

Migrating to Angular 9 + Ivy using ngx-translate duplicates translations terms

See original GitHub issue

Current behavior

I have migrated from angular 6 to angular 9 (following the official steps https://update.angular.io/ and all the libraries are migrated to the latest version now). I also use ngx-translate for the multi-language functionality.

Until now, using the syntax <span translate="cards" id="txt-cards"> Cards title</span> the text which is inside span was not displayed, instead the translation of the term was present.
In translation file en.json I have { “cards” : “Cards”}. So, in the browser, there was displayed the text Cards and the text " Cards title" from the span was omitted.

Now, the problem is that if a text is presented in the span, like “Cards title” in my example, the translation from cards.Cards is duplicated. SO, instead of displaying the text Cards, in the browser is displayed CardsCards.

This happens only If I set “enableIvy”: true in angularCompilerOptions, when building the app. IF this options is set to false, the issue is not presented.

Expected behavior

How do you think that we should fix this?

I am not sure if I should modify the entire app and remove the unnecessary texts or if there is something I should change in order to make it work.

Minimal reproduction of the problem with instructions

Environment


ngx-translate version: X.Y.Z
Angular version: X.Y.Z


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:open
  • Created 4 years ago
  • Reactions:8
  • Comments:7

github_iconTop GitHub Comments

3reactions
cexbrayatcommented, Mar 31, 2020

We just stumbled on the same issue, using Angular 9.0/Ivy and ngx-translate v12.

To be more accurate the problem occurs for us when using the translate directive without a dynamic input binding. For example:

<h1 [translate]="'home.title'">Some content</h1>

is fine, and displays only the translation of home.title. Whereas:

<h1 translate="home.title">Some content</h1>

displays home.title twice.

It can be reproduced in the unit-tests of the library itself by changing translate.directive.spec from the current:

<div #withKey [translate]="'TEST'">Some init content</div>
<div #withKey translate="TEST">Some init content</div>

The test then fails with TESTTEST instead of the expected TEST translated value.

1reaction
CarmenTalnariucommented, Mar 31, 2020

Hello, We fixed our problem by removing the text from the tag: instead of <h1 translate="home.title">Some content</h1> we are now having <h1 translate="home.title"></h1>

Read more comments on GitHub >

github_iconTop Results From Across the Web

Maintaining Multi-language Angular Applications with i18n
To translate templates in our application, we need first to prepare the texts by marking them with the i18n attribute. i18n is a...
Read more >
How to translate your Angular app with ngx-translate
1. Add ngx-translate to your Angular application 2. Set up the TranslateService in your app.module.ts 3. Create your main language translation file (in...
Read more >
NGX translate in Angular 9 - Stack Overflow
I'm having a problem using ngx translate on this project with Angular 9, it's not getting the translations that are in Assets.
Read more >
@ngx-translate/http-loader - npm package | Snyk
Finally, you can use ngx-translate in your Angular project. You have to import TranslateModule.forRoot() in the root NgModule of your application. The forRoot ......
Read more >
I18N for Angular microfrontends using Ngx-Locutus
Have you ever faced the issue of migrating a monolithical Angular application to a microfrontend architecture or just wanted to refactor your application ......
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