Some languages ignored when importing TBX
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.
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.
However Weblate could add support on top of that by using unit.getlanguageNode('de') internal API.
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.
https://github.com/translate/translate/pull/6310 should address this.
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.
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.
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
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
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.
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.
Let's keep this open for multi-language TBX support.