locl
locl copied to clipboard
Nested XLF placeholders/interpolations aren't properly converted to JSON
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.
- 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>
- Extract XLF with ng xi18n command
- Convert XLF to JSON with locl convert command
- 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
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="<a>" dispEnd="</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="<a>" dispEnd="</a>">
<ph id="1" equiv="INTERPOLATION" disp="{{ variable }}"/>
</pc>
</target>
JSON
"\n Some Text\n {$START_LINK}\n \n {$CLOSE_LINK}\n "
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}"