WeblateOrg / weblate

Web based localization tool with tight version control integration.
https://weblate.org/
GNU General Public License v3.0
4.63k stars 1.02k forks source link

XLIFF <file> tag not handled correctly for monolingual setup #3522

Closed mclei-asw closed 4 years ago

mclei-asw commented 4 years ago

Describe the bug When monolingual XLIFF setup is used, then newly translated texts ignores the "file" tag of source XLIFF and gets inserted in the first "file" tag in target XLIFF. It also generated non-valid XLIFF file with duplicated entries.

To Reproduce Steps to reproduce the behavior:

Source language file:

<?xml version='1.0' encoding='UTF-8'?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2" lang="en-US">
  <file original="APP.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="text_title">
        <source>Title</source>
      </trans-unit>
    </body>
  </file>
  <file original="MENU.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="appmenu_Open">
        <source>Open</source>
      </trans-unit>
    </body>
  </file>
</xliff>

Translated file:

<?xml version='1.0' encoding='UTF-8'?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2" lang="cz-CZ">
  <file original="APP.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="text_title">
        <source>Title</source>
      </trans-unit>
    </body>
  </file>
  <file original="MENU.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="appmenu_Open">
        <source>Open</source>
      </trans-unit>
    </body>
  </file>
</xliff>
  1. Create component with these files in Weblate
  2. Add new source text in the source file under second "file" tag (added appmenu_Close trans-unit):
    <?xml version='1.0' encoding='UTF-8'?>
    <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2" lang="en-US">
    <file original="APP.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="text_title">
        <source>Title</source>
      </trans-unit>
    </body>
    </file>
    <file original="MENU.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="appmenu_Open">
        <source>Open</source>
      </trans-unit>
      <trans-unit id="appmenu_Close">
        <source>Close</source>
      </trans-unit>
    </body>
    </file>
    </xliff>
  3. Translate all texts and commit.

The wrong result is: The appmenu_Close trans-unit gets inserted under first "file" tag.

<?xml version='1.0' encoding='UTF-8'?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2" lang="cz-CZ">
  <file original="APP.txt" source-language="en-US" datatype="x-asw" target-language="cs-CZ">
    <body>
      <trans-unit id="text_title">
        <source>Title</source>
        <target>Titulek</target>
      </trans-unit>
      <trans-unit id="appmenu_Close">
        <source>Close</source>
        <target>Zavřít</target>
      </trans-unit>
    </body>
  </file>
  <file original="MENU.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="appmenu_Open">
        <source>Open</source>
        <target>Otevřít</target>
      </trans-unit>
    </body>
  </file>
</xliff>

Expected result is: The appmenu_Close trans-unit must be inserted under second "file" tag.

<?xml version='1.0' encoding='UTF-8'?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2" lang="cz-CZ">
  <file original="APP.txt" source-language="en-US" datatype="x-asw" target-language="cs-CZ">
    <body>
      <trans-unit id="text_title">
        <source>Title</source>
        <target>Titulek</target>
      </trans-unit>
    </body>
  </file>
  <file original="MENU.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="appmenu_Open">
        <source>Open</source>
        <target>Otevřít</target>
      </trans-unit>
      <trans-unit id="appmenu_Close">
        <source>Close</source>
        <target>Zavřít</target>
      </trans-unit>
    </body>
  </file>
</xliff>

BUT it is getting even worse and generates NON-valid XLIFF file

  1. Add one more source text (appmenu_Quit trans-unit under second "file" tag):
    <?xml version='1.0' encoding='UTF-8'?>
    <xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2" lang="en-US">
    <file original="APP.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="text_title">
        <source>Title</source>
      </trans-unit>
    </body>
    </file>
    <file original="MENU.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="appmenu_Open">
        <source>Open</source>
      </trans-unit>
      <trans-unit id="appmenu_Close">
        <source>Close</source>
      </trans-unit>
      <trans-unit id="appmenu_Quit">
        <source>Quit</source>
      </trans-unit>
    </body>
    </file>
    </xliff>
  2. pull the changes in Weblate

Now the already translate trans-unit "appmenu_Close" shows as untranslated.

  1. translate again all texts and commit

The WRONG result is:

<?xml version='1.0' encoding='UTF-8'?>
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2" lang="cz-CZ">
  <file original="APP.txt" source-language="en-US" datatype="x-asw" target-language="cs-CZ">
    <body>
      <trans-unit id="text_title">
        <source>Title</source>
        <target>Titulek</target>
      </trans-unit>
      <trans-unit id="appmenu_Close">
        <source>Close</source>
        <target>Zavřít</target>
      </trans-unit>
      <trans-unit id="appmenu_Quit">
        <source>Quit</source>
        <target>Ukončit</target>
      </trans-unit>
      <trans-unit id="appmenu_Close">
        <source>Close</source>
        <target>Zavřít</target>
      </trans-unit>
    </body>
  </file>
  <file original="MENU.txt" source-language="en-US" datatype="x-asw">
    <body>
      <trans-unit id="appmenu_Open">
        <source>Open</source>
        <target>Otevřít</target>
      </trans-unit>
    </body>
  </file>
</xliff>

It means, that the trans-unit "appmenu_Close" gets duplicated!!!!

Server configuration and status The component configured as monolingual with source file in en-US.

weblate list_versions

nijel commented 4 years ago

Duplicate of #2482

mclei-asw commented 4 years ago

Why was this just closed? In the #2482, there is even not mentioned that the similar problem is also with "file" tag. There is only "group" tag discussed.

nijel commented 4 years ago

Because it's technically same issue, it doesn't matter whether it is file or group tag.