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 9 - i18n] Cannot use empty strings as translations anymore

See original GitHub issue

🐞 bug report

Affected Package

The issue is caused by package @angular/localize and/or Ivy (not sure). The crash happens here: https://github.com/angular/angular/blob/416c786774dccc20d824737207be4e55cb53c9cc/packages/core/src/render3/hooks.ts#L74

Is this a regression?

Yes, the last previous version in which this bug was not present was: Angular 8.2.14.

Description

When translating an app in different locales, it may be wanted to translate some strings to "". With Angular 8, it was possible to let some translation <target status="final"> with empty value in XLIFF 1.2 files. The result would be an empty HTML element. But with Angular 9, it seems not possible anymore. When a <target> is left empty and the corresponding bundle generated, the app crashes at this line when the page containing the empty target is rendered:

TypeError: Cannot read property 'directiveStart' of null

Please note that this crash only happens when the empty <target> concerns an HTML tag content. When the empty <target> concerns an HTML attribute translation, the app won’t crash.

🔬 Minimal Reproduction

Minimal reproduction available at: https://github.com/bravier/ng9-i18n-empty-xliff-target

I’ve generated this example using ng new myapp and added @angular/localize using the official documentation. The i18n tagged span is here.

Build steps:

  • npm install
  • npm run build
  • http-serve dist/myapp
  • Navigate to the /fr/ build and look at the console.

🌍 Your Environment

Angular Version:


Angular CLI: 9.1.0
Node: 10.15.0
OS: linux x64

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

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.901.0
@angular-devkit/build-angular     0.901.0
@angular-devkit/build-optimizer   0.901.0
@angular-devkit/build-webpack     0.901.0
@angular-devkit/core              9.1.0
@angular-devkit/schematics        9.1.0
@ngtools/webpack                  9.1.0
@schematics/angular               9.1.0
@schematics/update                0.901.0
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
braviercommented, Apr 8, 2020

Hi @AndrewKushnir,

I was able to test your fix using @adrienverge’s patch (I am still on 9.0.7) and I have the exact same results: no more crash and generated HTML looks as it was before in Angular 8.

Thank you for fixing it so quickly.

1reaction
adrienvergecommented, Apr 8, 2020

Hello @AndrewKushnir, thanks for the rapid answer.

I couldn’t test your change using the proposed method, because my app is not on 9.1.1 (I have to stay on 9.0 for other reasons). So I made the following patch from your PR (only the relevant parts), and applied it to my node_modules: handle-empty-translations-correctly-pr36499-angular9.0.7.patch.txt For users that have the same problem, you can apply it directly for Angular 9.0 using:

patch -p0 < handle-empty-translations-correctly-pr36499-angular9.0.7.patch.txt

Result: it works 🎉 No more crash, and generated HTML is fine (no tags being closed prematurely). Thanks @AndrewKushnir!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular i18next empty translation? - Stack Overflow
The problem is that if for instance for the key my:key I don't have any translation defined. I would like to show only...
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 >
9 biggest localization issues developers face (+ how to solve ...
1. Synchronizing translations between TMS and code repository. This task is probably the most common one for developers. We need to make sure ......
Read more >
Angular Language Service
In Visual Studio Code, install the extension from the Extensions: Marketplace. Open the marketplace from the editor using the Extensions icon on the...
Read more >
299049 – Cannot set a translation to the empty string - Bugs
I guess the "Non-Translatable" checkbox removes a string from the translated properties file (at least that's what I see for key " ...
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