You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
now ng-xi18n will generate xliff including spaces, for example there is an element
<p i18n>
复制
</p>
it will generate
<source>
复制
</source>
it's really weak to rely on spaces since they could changed Unintentionally or even by IDE reformat code.
Expected behavior
ignore leading and tailing spaces
Reacted by fredrikredflag, hworld, Panuruj Khambanonda (PK), Luke Ehresman, Carlos (Goodwine), Jonas Schürmann, moritz-h, 神楽坂玲奈, Lars Rye Jeppesen, Christoph Burgmer and 125 more
Reacted by Klemen Oslaj, Tommaso Cortese, Timur Mishagin, rosterathleticsadmin, Gabriel Dugny, Aurélien Dussauge and Norbert Kelemen
The more serious issue is that the ID takes the white space into account, and the ID could change just because of a change in the white space (e.g. indentation). The change in the ID prevents an existing translation from being used. I know that there is a feature to manually override the ID, but it would great if the generated ID can be more stable.
We could probably ignore the leading and trailing spaces yes, that would actually decrease the number of duplicated translations when we do the extraction and make the translations easier to do (with some software it's hard to reproduce the line breaks/tabs when you translate).
What do you think @vicb ?
<h4i18n>
{ids.length, plural,
=0 {You have not selected any country yet.}
=1 {You have selected the following country: }
other {You have selected the following countries: }
}
</h4>
will generate 2 messages after extraction:
<messagebundle>
<msgid="203167065070819173">
<phname="ICU"><ex>ICU</ex></ph>
</msg>
<msgid="5290485580948134395">{VAR_PLURAL, plural, =0 {You have not selected any country yet.} =1 {You have selected the following country: } other {You have selected the following countries: } }</msg>
</messagebundle>
because there are line breaks before and after the ICU expression. Removing them would fix this.
Reacted by Bishoy H.Louka, Minijus L, Philipp and Damian Kociszewski
Another case that should be handled is that changing indentation affects the generated message id. I believe the message extractor should replace(/\s+/, ' ') (or something like that).
In the examples below, a span tag is updated to be surrounded by a div tag, which doesn't change the visible contents and therefore should preserve the same id, but it doesn't.
Example:
<!-- initial version --><spani18n>
Some text.
Another Text.
</span><!-- updated version --><div><spani18n>
Some text.
Another Text.
</span></div>
These will generate something like:
<!-- initial version -->
<messagebundle>
<msgid="123">
Some text.
Another Text.
</msg>
</messagebundle>
<!-- updated version -->
<messagebundle>
<msgid="456">
Some text.
Another Text.
</msg>
</messagebundle>
One would expect that the actual generated message trims whitespaces (as OP suggests), and also transforms multiple whitespaces into a single one:
<messagebundle>
<msgid="123">Some text. Another Text.</msg>
</messagebundle>
Of course there is this problem then when the text is surrounded by a <pre> tag or css white-space:pre*, which I don't know what's the best way to solve without adding additional attributes to the tag that has i18n. e.g. <span i18n="desc" i18n-keepws>
Reacted by robertorfischer, Wei (Jack) Sun, Adrien Crivelli, XavierDupessey, Yoann Ouab, Yannik Hampe, Lazar Ljubenović, Ricardo Saracino and Alwin Schoemaker
I'd like to echo on this proposal. It seems stripping consecutive spaces is a more common use case. We can use additionally suffix (i18n-keepws) to tell message extractor not to do so if needed.
@Goodwine agreed, which is why I prefer the second option: put your tags at the lowest level (no nested html) and manage it that way. The browser often ignores non-explicit spaces anyway.
Since I also was annoyed by the whitespaces & I don't have any <pre> like messages involved I just quickly added the following workaround to my project.
I use a tiny little "hack" in order to clean the generated messages.xlf file after it was written by Angular CLI.
Combined with a npm script I now have exactly what I want with a single command.
For IntelliJ go to Settings | Editor | Code Style | HTML and inside Don't break if inline content add button and any other elements that may accidentally get a newline when you Reformat Code.
It's still a pain point for us. Without being able to use formatting tool (such as prettier) our template suffer quite a lot, unless we format manually which really is very 1990.
I meant to create a PR a while ago, but never got around to it. Not sure when I'd have time in the foreseeable future.
Also I was under the impression that the core team might want to resolve that themselve, instead of accepting a PR from the community. @petebacondarwin can you confirm or infirm that ?
Any news? I think Angular team should consider spending some time in refreshing the i18n part of the framework
Reacted by Minijus L, Mario Ivankovits, Konopyanov Manap, Marco Wüthrich, Yuri Beliakov, Roman Simoroshkin, Gabriel Dugny, vytautaszGG, Tyler Ballast, Aurélien Dussauge and 3 more
Reacted by Marco Wüthrich, Victor Zubrinkin, Håkan Svensson, rosterathleticsadmin, Denis Atyasov , Gabriel Dugny, vytautaszGG, Felix Jägers, Aurélien Dussauge, Francisco José Cadaval Arrola and 2 more
Since I also was annoyed by the whitespaces & I don't have any \<pre\> like messages involved I just quickly added the following workaround to my project.
I use a tiny little "hack" in order to clean the generated messages.xlf file after it was written by Angular CLI. Combined with a npm script I now have exactly what I want with a single command.
Activity
panuruj commentedon Mar 6, 2017
The more serious issue is that the ID takes the white space into account, and the ID could change just because of a change in the white space (e.g. indentation). The change in the ID prevents an existing translation from being used. I know that there is a feature to manually override the ID, but it would great if the generated ID can be more stable.
CC: @ocombe
ocombe commentedon Mar 6, 2017
We could probably ignore the leading and trailing spaces yes, that would actually decrease the number of duplicated translations when we do the extraction and make the translations easier to do (with some software it's hard to reproduce the line breaks/tabs when you translate).
What do you think @vicb ?
ocombe commentedon Mar 20, 2017
Another issue due to this:
will generate 2 messages after extraction:
because there are line breaks before and after the ICU expression. Removing them would fix this.
vicb commentedon Mar 21, 2017
Something we should work on for the next major release
Goodwine commentedon Mar 21, 2017
Another case that should be handled is that changing indentation affects the generated message id. I believe the message extractor should
replace(/\s+/, ' ')(or something like that).In the examples below, a
spantag is updated to be surrounded by adivtag, which doesn't change the visible contents and therefore should preserve the same id, but it doesn't.Example:
These will generate something like:
One would expect that the actual generated message trims whitespaces (as OP suggests), and also transforms multiple whitespaces into a single one:
Of course there is this problem then when the text is surrounded by a
<pre>tag or csswhite-space:pre*, which I don't know what's the best way to solve without adding additional attributes to the tag that has i18n. e.g.<span i18n="desc" i18n-keepws>[-]i18n ignore leading and tailing spaces[/-][+]i18n ignore leading and trailing spaces[/+]ocombe commentedon Sep 19, 2017
@pkozlowski-opensource do you think that we could make this work with your changes for whitespaces removal?
Jacksunwei commentedon Oct 27, 2017
I'd like to echo on this proposal. It seems stripping consecutive spaces is a more common use case. We can use additionally suffix (i18n-keepws) to tell message extractor not to do so if needed.
pmccloghrylaing commentedon Mar 20, 2018
@Jacksunwei would the existing
ngPreserveWhitespacesattribute be sufficient?49 remaining items
maplion commentedon Nov 13, 2021
@Goodwine agreed, which is why I prefer the second option: put your tags at the lowest level (no nested html) and manage it that way. The browser often ignores non-explicit spaces anyway.
gestj commentedon Jan 28, 2022
Since I also was annoyed by the whitespaces & I don't have any
<pre>like messages involved I just quickly added the following workaround to my project.I use a tiny little "hack" in order to clean the generated
messages.xlffile after it was written by Angular CLI.Combined with a npm script I now have exactly what I want with a single command.
Pimp it if needed depending on your use case.
clean-generated-xlf.jspackage.jsonhttps://regex101.com/r/lhCFwL/1
zkirill commentedon Jun 20, 2022
For IntelliJ go to Settings | Editor | Code Style | HTML and inside Don't break if inline content add
buttonand any other elements that may accidentally get a newline when you Reformat Code.ciriousjoker commentedon May 14, 2023
Any news? Is this on anyone's radar?
PowerKiKi commentedon May 15, 2023
It's still a pain point for us. Without being able to use formatting tool (such as prettier) our template suffer quite a lot, unless we format manually which really is very 1990.
I meant to create a PR a while ago, but never got around to it. Not sure when I'd have time in the foreseeable future.
Also I was under the impression that the core team might want to resolve that themselve, instead of accepting a PR from the community. @petebacondarwin can you confirm or infirm that ?
t-mish commentedon Jun 27, 2023
Any news? I think Angular team should consider spending some time in refreshing the i18n part of the framework
killStrikeFF commentedon Nov 30, 2023
We are waiting for this
yuriy-sng commentedon Feb 19, 2024
Oh look, another popular long-standing Angular bug 🙃
RenePapeKmd commentedon Mar 8, 2024
This solution works very well, but I had to add a plus to the two whitespace captures to replace i.e. repeated spaces.
So \s should be \s+ like:
patrickuhlmann commentedon Mar 27, 2024
We "fixed" the problem with the duplicate translations (with/without whitespace) by using prettier/eslint with the option https://prettier.io/blog/2018/11/07/1.15.0.html#whitespace-sensitive-formatting html-whitespace-sensitivity: strict. The resulting code had no whitespace in the tag content anymore.
t-mish commentedon Mar 27, 2024
@patrickuhlmann Same
NateRadebaugh commentedon Oct 3, 2025
@JoostK @JeanMeche is this something that will ever be fixed or should work figure out some bad workarounds in user-land?