Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. I18n: lupdate adds duplicate <location> tag after every build

I18n: lupdate adds duplicate <location> tag after every build

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 529 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Spessi
    wrote on last edited by
    #1

    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:

    1. Open QtCreator 9.0.1.

    2. Create new "Qt Widgets Application" named "DemoApp".

    3. Choose Build System "CMake".

    4. Continue to wizard step "Translation File", choose a language (in my case "German (Germany)").

    5. Select kit "Desktop Qt 6.4.1 MSVC 2019 64bit".

    6. 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!

    1 Reply Last reply
    1
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Seems to be a bug: QTBUG-109316.
      There's a workaround in the comments - remove the ts file from the source list.

      1 Reply Last reply
      3
      • S Offline
        S Offline
        Spessi
        wrote on last edited by Spessi
        #3

        Thank you for your response. Although I searched for a bug report, I didn't find it. Thanks for suggesting the workaround.

        Edit: unfortunately, the *.ts files won't appear in the project overview in QtCreator anymore. But that's ok for now.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved