daniel-sc / ng-extract-i18n-merge

Extract and merge i18n xliff translation files for angular projects.
MIT License
178 stars 19 forks source link

Space between interpolated statements sometimes removed #17

Closed Andrew-Marks-Trisept closed 2 years ago

Andrew-Marks-Trisept commented 2 years ago

When there are multiple interpolated statements in a row with a space in between, the space is sometimes removed. This only seems to happen as the message gets more complex. Consider the following examples:

HTML

<span i18n="@@myTestId">{{ myLabel }} {{ myNumber }}</span>
<span i18n="@@myTestId2">Some text {{ myLabel }} {{ myNumber }}</span>

.ts

myLabel: string = 'Thing';
myNumber: number = 1;

xlf Output

<unit id="myTestId">
  <segment state="final">
    <source>
      <ph id="0" equiv="INTERPOLATION" disp="{{ myLabel }}"/>
      <ph id="1" equiv="INTERPOLATION_1" disp="{{ myNumber }}"/>
    </source>
    <target>
      <ph id="0" equiv="INTERPOLATION" disp="{{ myLabel }}"/>
      <ph id="1" equiv="INTERPOLATION_1" disp="{{ myNumber }}"/>
    </target>
  </segment>
</unit>
<unit id="myTestId2">
  <segment state="final">
    <source>Some text <ph id="0" equiv="INTERPOLATION" disp="{{ myLabel }}"/><ph id="1" equiv="INTERPOLATION_1" disp="{{ myNumber }}"/></source>
    <target>Some text <ph id="0" equiv="INTERPOLATION" disp="{{ myLabel }}"/><ph id="1" equiv="INTERPOLATION_1" disp="{{ myNumber }}"/></target>
  </segment>
</unit>

The first example works and outputs Thing 1 -- I think by virtue of the line break in between the <ph> elements?

The second example outputs Some text Thing1 when it should be Some text Thing 1.

Andrew-Marks-Trisept commented 2 years ago

So I was thinking maybe this wasn't related to this library, because it's like that in the extracted source file. I thought maybe something changed in Angular 13.

But then I went back and ran the default ng extract-i18n script like I used to and sure enough, the space was added properly. Any idea what the difference would be? I assumed your extract-i18n-merge just ran extract-i18n in the background.

Maybe something with the alphabetizing of the nodes causes this?

daniel-sc commented 2 years ago

@Andrew-Marks-Trisept can you please check if v1.2.2 fixes this?

Andrew-Marks-Trisept commented 2 years ago

Yes, it does. Thanks again!