Skip to content

i18n: $localize extraction should handle ES5 concatenated strings #36937

@bravier

Description

@bravier

🐞 bug report

Affected Package

The issue is caused by package @angular/localize.

Description

I know using $localize in TypeScript is still unofficially supported and undocumented but it works fine for us in most cases except for multi-line strings.

When using the $localize tag function on a multi-line template literal, whitespaces are taken into account in the computation of the message ID.

This results in different IDs for the same string and multiple trans-units in the XLIFF file for the same translation.

In our use case, we need to split long translated strings to keep our code correctly formatted.

I am not sure this is an expected behavior or an issue.

If this is the expected behavior, is there a way to keep using multi-line template literals and ignoring whitespaces to keep the ID unique?

One solution would be to remove whitespaces by formating template literal to start at the beginning of lines. But it breaks code formatting (see title3 in app.component.ts).

🔬 Minimal Reproduction

Minimal reproduction available at: https://github.com/bravier/localize-multi-line

I've generated this example using ng new and added @angular/localize using the official documentation.

See app.component.ts where I translate the same string with only one space added in title2 to keep the lines correctly indented.

Build steps:

  • npm install
  • npm run build
  • http-serve dist/localize-multi-line

🌍 Your Environment

Angular Version:


Angular CLI: 9.1.4
Node: 12.16.3
OS: linux x64

Angular: 9.1.4
... 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.4
@angular-devkit/build-angular     0.901.4
@angular-devkit/build-optimizer   0.901.4
@angular-devkit/build-webpack     0.901.4
@angular-devkit/core              9.1.4
@angular-devkit/schematics        9.1.4
@ngtools/webpack                  9.1.4
@schematics/angular               9.1.4
@schematics/update                0.901.4
rxjs                              6.5.5
typescript                        3.8.3
webpack                           4.42.0

Metadata

Metadata

Labels

area: i18nIssues related to localization and internationalizationfeatureIssue that requests a new featurefeature: insufficient votesLabel to add when the not a sufficient number of votes or comments from unique authorsfeature: votes requiredFeature request which is currently still in the voting phase

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions