I18n: lupdate adds duplicate <location> tag after every build
-
Hi,
I'm working on a CMake based Qt Widget project which uses qt_create_translation to add the lupdate/lrelease build targets. As soon as I'm using the tr("...") method in a cpp file, the call of lupdate creates a new<location filename="mainwindow.cpp" line="10"/>
entry in the *.ts file. After 10 builds there are 10 identical <location ...> entries in the <message></message> section (see later). After a lot of builds, the *.ts file has much more redundant <location> tags than actual translation information; it's messed up.
I made a minimal demo application which reproduces the behaviour:
-
Open QtCreator 9.0.1.
-
Create new "Qt Widgets Application" named "DemoApp".
-
Choose Build System "CMake".
-
Continue to wizard step "Translation File", choose a language (in my case "German (Germany)").
-
Select kit "Desktop Qt 6.4.1 MSVC 2019 64bit".
-
In the generated CMakeLists.txt, replace the line
qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
by
qt_add_translations(DemoApp TS_FILES ${TS_FILES})
as qt_create_translation is deprecated. In addition, qt_add_translations properly sets up the build targets "update_translations" and "release_translations".
7. In QtCreator, open the "Projects" tab, select Build & Run -> Build and expand the "Build Steps" details. Tick "update_translations" and "release_translations".
8. Open mainwindow.cpp and add "qInfo() << tr("Hello World");".
9. Build the project, the DemoApp_de_DE.ts gets updated.This is the DemoApp_de_DE.ts after the first build:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.1" language="de_DE"> <context> <name>MainWindow</name> <message> <location filename="mainwindow.ui" line="14"/> <location filename="../build-DemoApp-Desktop_Qt_6_4_1_MSVC2019_64bit-Debug/DemoApp_autogen/include/ui_mainwindow.h" line="50"/> <source>MainWindow</source> <translation type="unfinished"></translation> </message> <message> <location filename="mainwindow.cpp" line="10"/> <source>Hello World</source> <translation type="unfinished"></translation> </message> </context> </TS>
This is the DemoApp_de_DE.ts after the 10th build:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> <TS version="2.1" language="de_DE"> <context> <name>MainWindow</name> <message> <location filename="mainwindow.ui" line="14"/> <location filename="mainwindow.ui" line="14"/> <location filename="../build-DemoApp-Desktop_Qt_6_4_1_MSVC2019_64bit-Debug/DemoApp_autogen/include/ui_mainwindow.h" line="50"/> <source>MainWindow</source> <translation type="unfinished"></translation> </message> <message> <location filename="mainwindow.cpp" line="10"/> <location filename="mainwindow.cpp" line="10"/> <location filename="mainwindow.cpp" line="10"/> <location filename="mainwindow.cpp" line="10"/> <location filename="mainwindow.cpp" line="10"/> <location filename="mainwindow.cpp" line="10"/> <location filename="mainwindow.cpp" line="10"/> <location filename="mainwindow.cpp" line="10"/> <location filename="mainwindow.cpp" line="10"/> <location filename="mainwindow.cpp" line="10"/> <source>Hello World</source> <translation type="unfinished"></translation> </message> </context> </TS>
Is this a bug or am I doing something wrong? As far as I've researched this only happens to tr(...) strings, not to strings located in *.ui files.
Thank you for your time and help!
-
-
Seems to be a bug: QTBUG-109316.
There's a workaround in the comments - remove the ts file from the source list. -