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?
From the lupdate
man page:
-locations
{absolute
|relative
|none
}Specify/override how source code references are saved in
ts
files. Default isabsolute
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With