Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpolation get removed after translation done #810

Open
danjor opened this issue May 18, 2022 · 9 comments
Open

Interpolation get removed after translation done #810

danjor opened this issue May 18, 2022 · 9 comments

Comments

@danjor
Copy link

danjor commented May 18, 2022

I'm using xliff 1.2 files.
After translating fields from the webapp, interpolation tags get removed from the target.

<trans-unit id="1014715239941102606" datatype="html">
        <source>Remove <x id="linkedMethodName" equiv-text="name"/> </source>
        <target>Remove <x id="linkedMethodName" equiv-text="name"/> </target>
        <note priority="1" from="description">Action verb</note>
</trans-unit>

become

<trans-unit id="1014715239941102606" datatype="html">
        <source>Remove <x id="linkedMethodName" equiv-text="name"/> </source>
        <target>Supprimer</target>
        <note priority="1" from="description">Action verb</note>
</trans-unit>

Then, it can't be used like this for Angular app.

@aurambaj
Copy link
Collaborator

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?

@danjor
Copy link
Author

danjor commented May 19, 2022

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.
image
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.

@ehoogerbeets
Copy link
Contributor

ehoogerbeets commented May 19, 2022

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 &lt;x id="message" equiv-text="message"/&gt;? This action is irreversible.</source>
			<target xml:lang="fr-FR">Do you really want to delete &lt;x id="message" equiv-text="message"/&gt;? This action is irreversible.</target>
		</trans-unit>
	<body>
  </file>
</xliff>

@danjor
Copy link
Author

danjor commented May 19, 2022

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?

@danjor
Copy link
Author

danjor commented May 19, 2022

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

@ehoogerbeets
Copy link
Contributor

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.

@aurambaj
Copy link
Collaborator

@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

@ehoogerbeets
Copy link
Contributor

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.

@danjor
Copy link
Author

danjor commented May 20, 2022

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.

image

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 &lt;x id="linkedMethodName" equiv-text="this.linkedMethods.value[index].name"/&gt;</source>
        <note priority="1" from="description">Action verb</note>
</trans-unit>

exported translation file (pull)

<trans-unit id="1014715239941102606" datatype="html">
        <source>Remove &lt;x id="linkedMethodName" equiv-text="this.linkedMethods.value[index].name"/></source>
        <target xml:lang="fr-FR">Suppr &lt;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.
/(\&lt;x(\s+([^\/]*))\/>)/gi instead of /(\&lt;x(\s+([^\/]*))\/\&gt;)/gi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants