Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for Qt translations and git

Tags:

Today I tried to merge two git branches of a Qt project. Both branches had added some new strings and new translations for them. Now Qt's lupdate tool stores the line number of the source file where the translation is needed in the .ts files. As you can imagine the line numbers are not identical for two branches and when both translation files have been updated, this leads to hundreds of merge conflicts like this, for every single translation file:

<<<<<<< HEAD
 +        <location filename="../../src/network/mail/CSmtp.cpp" line="856"/>
=======
+         <location filename="../../src/network/mail/CSmtp.cpp" line="860"/>
>>>>>>> master

You might say just use one of the versions and run lupdate again, but that way you lose all new translations from one of the branches.

Other tools, like gettext, don't not have this problem, since they do not store line numbers.

What are some good approaches to avoid this problem in Qt?

like image 876
SteakOverflow Avatar asked Jan 29 '15 17:01

SteakOverflow


2 Answers

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!

like image 62
Toby Speight Avatar answered Sep 22 '22 12:09

Toby Speight


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.

like image 45
VonC Avatar answered Sep 24 '22 12:09

VonC