Best practice for Qt translations and git Best practice for Qt translations and git git git

Best practice for Qt translations and git


From the lupdate man page:

-locations {absolute|relative|none}

Specify/override how source code references are saved in ts files. Default is absolute.

So use lupdate -locations none to eliminate all line numbers in the TS files. Use lupdate -locations relative to reduce the churn in line numbers: now, changes in line numbers will only affect the first string after each change, which might be an acceptable compromise if you use linguist with the source window open.

My preference is to commit to source-control just the version with -locations none. Any time I need the line numbers, I run lupdate locally to generate a temporary version with absolute locations. Make sure you don't commit the temporary!


One possible solution (mentioned in an answer to "Merge translation files (.ts) with existing .ts files") is to use lconvert. When this was introduced, in Qt 4.5:

The new lconvert filter tool facilitates conversion between file formats and can be used to perform other transformations on collections of translatable strings.

It involves a manual step (creating a second file with only the strings you want to merge), and then:

 lconvert -i primary.ts secondary.ts -o complete.ts

To complete the end result, the answer to "Translation file still working after modifying the source?" also mentions pylupdate4 your_project.pro as a way to update all the references to the lines in the ts file.


You can drop the line numbers with lupdate too using -locations none. This will eliminate any conflicts with line numbers but you will loose the context of the strings in the sources. For .ui files there is also -no-ui-lines argument.

lupdate -locations none -no-ui-lines ...