weblate icon indicating copy to clipboard operation
weblate copied to clipboard

Some languages ignored when importing TBX

Open danielnaber opened this issue 11 years ago • 11 comments

I'm not very familiar with TBX, but according to a DTD validation, this should be valid TBX (TBX-Basic, actually):

    <body>
        <termEntry id="c5">
            <langSet xml:lang="en"><tig><term>English term</term></tig></langSet>
            <langSet xml:lang="de"><tig><term>German term</term></tig></langSet>
            <langSet xml:lang="es"><tig><term>S</term></tig></langSet>
        </termEntry>
    </body>

I can import this to the German translation and it works as expected, but when I import it to the Spanish translation, the German term gets imported as translation. It seems as if the xml:lang is ignored.

danielnaber avatar Sep 14 '15 13:09 danielnaber

Indeed, translate-toolkit doesn't seem to look at the xml:lang attribute at all - it always picks the fist two langSet entries, taking first one as source and second one as target.

nijel avatar Sep 14 '15 13:09 nijel

However Weblate could add support on top of that by using unit.getlanguageNode('de') internal API.

nijel avatar Sep 14 '15 14:09 nijel

Even with only two languages, having the <langSet>s in a different order will lead to wrong data being imported. For example:

    <body>
        <termEntry id="c5">
            <langSet xml:lang="de"><tig><term>German term</term></tig></langSet>
            <langSet xml:lang="en"><tig><term>English term</term></tig></langSet>
        </termEntry>
    </body>

will lead to "German term" in English and "English term" in German.

This reliance on the ordering is not conformant with the specs and breaks importing TBX generated by other tools.

Can this be re-classified as a bug? In my view #11039 should not block this issue. The reporter expected to have to upload the same file twice to two different languages, but not that the language gets ignored.

It would be great if on import the two languages needed would be filtered out of the TBX via the internal API described in the comment above.

michael-smt avatar Apr 02 '26 12:04 michael-smt

https://github.com/translate/translate/pull/6310 should address this.

nijel avatar May 13 '26 11:05 nijel

Thanks a lot for addressing this @nijel. It works nicely when the entry list is complete. But with missing entries in the target language, it will fall back to a different language, leading to unexpected results.

    <body>
        <termEntry id="c5">
            <langSet xml:lang="de"><tig><term>German term</term></tig></langSet>
            <langSet xml:lang="en"><tig><term>English term</term></tig></langSet>
            <langSet xml:lang="es"><tig><term>Spanish term</term></tig></langSet>
        </termEntry>
        <termEntry id="c6">
            <langSet xml:lang="de"><tig><term>German second term</term></tig></langSet>
            <langSet xml:lang="en"><tig><term>English second term</term></tig></langSet>
        </termEntry>
    </body>

When importing the above into Spanish, you get "German second term" for the second entry, instead of keeping it empty.

michael-smt avatar May 19 '26 14:05 michael-smt

Hmm, I tried to be conservative in rejecting input, as there might be people having completely wrong language tags in the TBX files, and it worked up to now. It's difficult to draw the line between what is still a compatible desired behavior and what should be rejected.

nijel avatar May 20 '26 06:05 nijel

I understand the reasoning, would it make sense to have a separate "TBX with language tags" format instead?

It seems in TBX v2 such tags are required:

Every element containing free text shall have the language of that text indicated by having an explicit or inherited xml:lang attribute https://www.tbxinfo.net/wp-content/uploads/2016/10/tbx_oscar.pdf#page=20

michael-smt avatar May 20 '26 09:05 michael-smt

Indeed they are required, but that doesn't mean that everybody follows the specification 😄. But let's try to be strict and deal with the issues in case they appear: https://github.com/translate/translate/pull/6339

nijel avatar May 28 '26 11:05 nijel

Thanks a lot for fixing this. Can confirmed that importing the same file twice into to two different translations picks the correct language. IMHO this issue can be closed as it solves the original request.

michael-smt avatar Jun 18 '26 09:06 michael-smt

Side note: when a TBX file contains a <note from="translator"> entry in each different <langSet> they are all imported into the same translation string explanation.

michael-smt avatar Jun 18 '26 13:06 michael-smt

Let's keep this open for multi-language TBX support.

nijel avatar Sep 08 '26 08:09 nijel