Open danjor opened 2 years ago
could you screenshot the string in the webapp/worbench. Does it show the Remove <x id="linkedMethodName" equiv-text="name"/>
as plain text in the source? Have you kept it in the target as well?
Interpolation in not shown in the webapp
:/xlf/MyRepo# mojito repo-create -n MyRepo -l fr-FR
Create repository: MyRepo
Extracting locale: fr-FR
Extracted RepositoryLocale:
-- bcp47Tag = fr-FR
-- isFullyTranslated = true
created --> repository id: 2
:/xlf/MyRepo# mojito push -r MyRepo -s /xlf/MyRepo/ -sr "^resources.xliff$"
Push assets to repository: MyRepo
- Uploading: resources.xliff
--> asset id: 2, task: 13
Running, task id: 13
Creating asset: resources.xliff (14) Done
Process asset content, id: 2 (15) Done
Extracting text units from asset (16) Done
Create new text units (17) Done
Updating branch asset text units (19) Done
Updating merged asset text units (21) Done
Perform leveraging (22) Done
Finished
Interpolation is not displayed in the webapp. I'm not editing the translation and simply export using pull.
:/xlf/MyRepo# mojito pull -r MyRepo -s /xlf/MyRepo -t /xlf/MyRepoOut
Pull localized asset from repository: MyRepo
Localizing: resources.xliff
- Processing locale: fr-FR --> resources_fr-FR.xliff
resources.xliff from push was :
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en-US" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="delete-service-warning" datatype="html">
<source>Do you really want to delete <x id="message" equiv-text="message"/>? This action is irreversible.</source>
</trans-unit>
<body>
</file>
</xliff>
without editing nothing in the webapp, resulting resources_fr-FR.xliff from pull was :
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en-US" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="delete-service-warning" datatype="html">
<source>Do you really want to delete <x id="message" equiv-text="message"/>? This action is irreversible.</source>
<target xml:lang="fr-FR">Do you really want to delete ? This action is irreversible.</target>
</trans-unit>
<body>
</file>
</xliff>
Target interpolation has been removed, but should be kept.
The x tag is not part of the xliff xml schema, so the parser will drop it. If you want an xml element to be a part of the string in an xliff string, the "<" characters need to be escaped:
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en-US" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="delete-service-warning" datatype="html">
<source>Do you really want to delete <x id="message" equiv-text="message"/>? This action is irreversible.</source>
<target xml:lang="fr-FR">Do you really want to delete <x id="message" equiv-text="message"/>? This action is irreversible.</target>
</trans-unit>
<body>
</file>
</xliff>
Thanks for you reply.
Sadly Angular does not escape its own xml tag for interpolation in source tag when extracting messages from ts and html.
I'm afraid mojito can't be used out of the box for Angular xlf files that for sure will have a trans-unit with interpolation.
Shouldn't this be handled by mojito, by updating the parser or something?
I found a script for escape and replace angular <x interpolation tags. I will also try with this.
https://gist.github.com/jacob-jonkman/cc48d1f3690bc1accf9f36881e09ef47
https://gist.github.com/jacob-jonkman/2d5d26df672376bc31cd08710708a96b
Yes, those look like a good solution and that it would work. I think it might be difficult to update the parser in mojito because it is a 3rd party parser and it uses the xml schema to enforce the structure of the xliff, so this escaping/unescaping is a good workaround.
@ehoogerbeets what's your source for saying <x>
is not Xliff schema. I was under the impression it is, at least as specified here: http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html
Oh wow! I did not know about that! I guess it is part of the xliff schema. I guess the parser has a bug then.
I used the previous script to escape <x tags and then push, also import and pull. <x tags are correctly displayed in the webapp and kept in the exported translation file. So it seems to work as expected by escaping interpolation tags.
resources.xliff without escaping interpolation tags
<trans-unit id="1014715239941102606" datatype="html">
<source>Remove <x id="linkedMethodName" equiv-text="this.linkedMethods.value[index].name"/></source>
<note priority="1" from="description">Action verb</note>
</trans-unit>
escaped resources.xliff (push)
<trans-unit id="1014715239941102606" datatype="html">
<source>Remove <x id="linkedMethodName" equiv-text="this.linkedMethods.value[index].name"/></source>
<note priority="1" from="description">Action verb</note>
</trans-unit>
exported translation file (pull)
<trans-unit id="1014715239941102606" datatype="html">
<source>Remove <x id="linkedMethodName" equiv-text="this.linkedMethods.value[index].name"/></source>
<target xml:lang="fr-FR">Suppr <x id="linkedMethodName" equiv-text="this.linkedMethods.value[index].name"/></target>
<note from="description" priority="1">Action verb</note>
</trans-unit>
edit : in fact exported file (pull) has kept the opening <x tag escaped but unescaped the closing tag !
I could update the unescape script to handle this, even if it's strange.
/(\<x(\s+([^\/]*))\/>)/gi instead
of /(\<x(\s+([^\/]*))\/\>)/gi
I'm using xliff 1.2 files. After translating fields from the webapp, interpolation tags get removed from the target.
become
Then, it can't be used like this for Angular app.