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

State is set back to translated even if source did not change #128

Open
hansmaad opened this issue Apr 4, 2019 · 3 comments
Open

State is set back to translated even if source did not change #128

hansmaad opened this issue Apr 4, 2019 · 3 comments
Labels

Comments

@hansmaad
Copy link

hansmaad commented Apr 4, 2019

Hi,
if I understood correctly, the state should switch from final to translated, when the source changed. If nothing changed, the translation is untouched.

Please check this simple example, which will always set the state back to translated after setting the target state to final.

messages.xlf

<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
  <file source-language="de" datatype="plaintext" original="ng2.template">
    <body>
      <trans-unit id="global--formfield-too-large" datatype="html">
        <source>
        Der Wert ist zu groß</source>
        <context-group purpose="location">
          <context context-type="sourcefile">awesome.component.html</context>
          <context context-type="linenumber">2</context>
        </context-group>
      </trans-unit>
    </body>
  </file>
</xliff>

messages.en.xlf

<?xml version="1.0" encoding="utf-8"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
  <file datatype="plaintext" date="2018-11-14T14:52:51.3060268Z" original="3223941_9" source-language="de" target-language="en">
    <body>
      <trans-unit id="global--formfield-too-large" datatype="html">
        <source>
        Der Wert ist zu groß</source>
        <target state="final">
        The value is too large</target>
        <context-group purpose="location">
          <context context-type="sourcefile">awesome.component.html</context>
          <context context-type="linenumber">2</context>
        </context-group>
      </trans-unit>
    </body>
  </file>
</xliff>

If you remove whitespace from the source and target, it works as expected:

messages.xlf

<source>Der Wert ist zu groß</source>
<target state="translated">The value is too large</target>

I'm using this profile

{
    "$schema": "./node_modules/ngx-i18nsupport/dist/xliffmerge/configuration-schema.json",
    "xliffmergeOptions": {
      "srcDir": "src/i18n",
      "genDir": "src/i18n",
      "i18nBaseFile": "messages",
      "defaultLanguage": "de",
      "languages": ["de", "en"],
      "targetPraefix": "",
      "targetSuffix": "",
      "beautifyOutput": false,
      "allowIdChange": false,
      "autotranslate": false,
      "apikey": "",
      "apikeyfile": "",
      "verbose": false,
      "quiet": false
    }
  }
@hansmaad
Copy link
Author

hansmaad commented Apr 4, 2019

I figured out that it is a problem of \n in the source file vs. \r\n in the translation file (generated by TinyTranslator on Chrome Win10). The comparison here returns true:

if (transUnit.supportsSetSourceContent() && masterTransUnit.sourceContent() !== transUnit.sourceContent()) {
transUnit.setSourceContent(masterTransUnit.sourceContent());
if (isDefaultLang) {
// #81 changed source must be copied to target for default lang
transUnit.translate(masterTransUnit.sourceContent());
transUnit.setTargetState(STATE_FINAL);
} else {
if (transUnit.targetState() === STATE_FINAL) {
// source is changed, so translation has to be checked again
transUnit.setTargetState(STATE_TRANSLATED);
}
}
correctSourceContentCount++;
}

As a workaround I'm now using this npm script

"xi18n": "npm run xi18n:crlf && ng xi18n --i18n-locale de --output-path i18n && npm run xi18n:merge",
"xi18n:crlf": "crlf --set=LF src/i18n/*.xlf",
"xi18n:merge": "xliffmerge --profile xliffmerge.json en de"

@martinroob
Copy link
Owner

Yes, this is clearly a bug.
Thanks for already figuring out what the problem is.
Will fix it soon.

@hansmaad
Copy link
Author

hansmaad commented Sep 4, 2019

Unfortunately still broken for me.

Check out this example master (with LF). The corresponing translation file has same content but with CRLF.

<?xml version="1.0" encoding="UTF-8" ?>
<!-- issue 128 when source is unchanged but has different line ending translation state should not change -->
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="de" datatype="plaintext" original="ng2.template">
        <body>
            <trans-unit id="issue128" datatype="html">
                <source>
                Erste Zeile.
                Zweite Zeile.
                </source>
                <context-group purpose="location">
                    <context context-type="sourcefile">awesome.component.html</context>
                    <context context-type="linenumber">2</context>
                </context-group>
            </trans-unit>
        </body>
    </file>
</xliff>

@martinroob martinroob reopened this Oct 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants