Main menu

29 Jan 2025

Changes to Qt Linguist file exports

Loco has supported TS file exports since 2013, but our integration with this format has several problems which we're beginning to fix today.

To start with, we've fixed the ID-based export to include the correct id attribute, and place source text in the <source> element (including when the translation is empty). The default (text-based) export remains unchanged for the time being.

This is a breaking change, but we don't expect the previously incorrect output was useful in normal cases. You can reproduce the old behaviour by appending ts-legacy to the export URL query string.

Previous (incorrect) output

<!-- THIS IS WRONG -->
<TS version="2.1" sourcelanguage="en" language="de">
  <context>
    <name>main</name>
    <message>
      <source>txt1</source>
      <translation>Rückseite</translation>
    </message>
  </context>
</TS>

Corrected output:

<TS version="2.1" sourcelanguage="en" language="de">
  <context>
    <name></name>
    <message id="txt1">
      <source>Back</source>
      <translation>Rückseite</translation>
    </message>
  </context>
</TS>
  • Note the single <context> element with no name. Our understanding is that this doesn't apply when IDs are used.
  • We're aware the source element may not be required at runtime, but it seems harmless to include and makes the file more portable.

Context and disambiguation

On our roadmap is a bigger issue with text-based exports. This is the default for our TS implementation.

Loco's context field follows the Gettext concept of msgctxt, which is analogous to Qt's disambiguating <comment> string. But when we implemented Qt support (12 years ago) we wrongly mapped our context field to the <context> element, which we now understand is more like a unique namespace, or "domain".

This can't be fixed simply by correcting our TS file export, but we shall work towards a solution that doesn't break existing projects.

Relevant Qt documentation

Last updated by