locl icon indicating copy to clipboard operation
locl copied to clipboard

Nested XLF placeholders/interpolations aren't properly converted to JSON

Open alvarlariviere opened this issue 4 years ago • 2 comments

Issue description

Nested XLF placeholders/interpolations aren't properly converted to JSON.

Steps to reproduce the issue

Similar to https://github.com/loclapp/locl/issues/10 but with nested HTML elements.

  1. In an HTML template, define an i18n element which, in turn, contains another i18n element that contains interpolation
<p i18n="@@myId">
    Some Text
    <a [href]="..." i18n-title="@@myOtherId" title="Some other text">
        {{ someProp }}
    </a>
</p>
  1. Extract XLF with ng xi18n command
  2. Convert XLF to JSON with locl convert command
  3. Load JSON in app with loadTranslations

What's the expected result?

{
    "locale": "en-US",
    "translations": {
        "myId": "Some Text {$START_LINK}{$INTERPOLATION}{$CLOSE_LINK}",
        "myOtherId": "Some other text"
    }
}

What's the actual result?

{
    "locale": "en-US",
    "translations": {
        "myId": "Some Text {$START_LINK}{$CLOSE_LINK}",
        "myOtherId": "Some other text"
    }
}

Additional details

@locl/core": "0.0.1-beta.2 @locl/cli": "0.0.1-beta.6 Angular 9.0.4 XLIFF 2.0

alvarlariviere avatar Feb 18 '20 13:02 alvarlariviere

I've tested it further and it seems to only happening when there're newlines in the definition of the target XLF.

Correct Conversion

XLF

<target>Some Text <pc id="0" equivStart="START_LINK" equivEnd="CLOSE_LINK" type="link" dispStart="&lt;a>" dispEnd="&lt;/a>"><ph id="1" equiv="INTERPOLATION" disp="{{ variable }}"/></pc></target>

JSON

"Some Text {$START_LINK}{$INTERPOLATION}{$CLOSE_LINK}"

Wrong Conversion

XLF

<target>
    Some Text
    <pc id="0" equivStart="START_LINK" equivEnd="CLOSE_LINK" type="link" dispStart="&lt;a>" dispEnd="&lt;/a>">
        <ph id="1" equiv="INTERPOLATION" disp="{{ variable }}"/>
    </pc>
</target>

JSON

"\n        Some Text\n        {$START_LINK}\n          \n        {$CLOSE_LINK}\n      "

alvarlariviere avatar Feb 28 '20 23:02 alvarlariviere

I have this code in my html:

<span i18n="@@itemHeaderNewName">
    {{item.get('itemId')?.value ? "*" : "New item"}}
</span>

Do you know if it's possible to translate "*" and "New item"? This is how the locl converts it: @@itemHeaderNewName: "{$INTERPOLATION}"

Estevete avatar Nov 20 '20 15:11 Estevete