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. ID based translation with CMAKE creates superfluous entries in TS file
Forum Updated to NodeBB v4.3 + New Features

ID based translation with CMAKE creates superfluous entries in TS file

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 278 Views 2 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.
  • DialecticusD Offline
    DialecticusD Offline
    Dialecticus
    wrote on last edited by Dialecticus
    #1

    Follow these steps to see the issue. Use Windows OS. Create new "Qt Widgets Application" project. Name it "Testing". Use CMAKE build system. Select "English (United States)" as language (I assume you have this language installed in the system). Use "Desktop Qt 6.6.1 MSVC2019 64bit" kit.

    In CMakeLists.txt file replace qt_create-translation with qt_add_translation. The code should look like this (if the project is named "Testing":

    #qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
    qt_add_translations(Testing
        TS_FILES ${TS_FILES}
        RESOURCE_PREFIX "i18n"
        LUPDATE_OPTIONS -locations none -no-ui-lines -no-obsolete
        LRELEASE_OPTIONS -idbased)
    add_dependencies(Testing Testing_lupdate)
    add_dependencies(Testing update_translations)
    

    Open MainWindow.ui. Go to menu Tools > Form Editor > Form Settings. In new dialog select check box ID-based. Close the .ui, and build the project. The first time you build the project the file Testing_en_US.ts should look like this:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE TS>
    <TS version="2.1" language="en_US">
    <context>
        <name>MainWindow</name>
        <message>
            <source>MainWindow</source>
            <translation type="unfinished"></translation>
        </message>
    </context>
    </TS>
    

    Open the .ui file again. windowTitle property now has id sub-property. Set id value to "id-title", and build the project again. The .ts file now looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE TS>
    <TS version="2.1" language="en_US">
    <context>
        <name>MainWindow</name>
        <message id="id-title">
            <source>MainWindow</source>
            <translation type="unfinished"></translation>
        </message>
    </context>
    </TS>
    

    A little bit confusing that there is a context, because ID based translation model should be contextless, but fine, whatever. BUT, now rebuild the project. The .ts file NOW looks like this:

    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE TS>
    <TS version="2.1" language="en_US">
    <context>
        <name></name>
        <message>
            <source>id-title</source>
            <translation type="unfinished"></translation>
        </message>
    </context>
    <context>
        <name>MainWindow</name>
        <message id="id-title">
            <source>MainWindow</source>
            <translation type="unfinished"></translation>
        </message>
    </context>
    </TS>
    

    Is this a bug, or am I doing something wrong? I don't expect two entries for the same translation term.

    This new entry is actually ignored by the code. Add translation to the <message id="id-title"> entry and it will appear in window title. Entry <source>id-title</source> is not used.

    Christian EhrlicherC 1 Reply Last reply
    0
    • DialecticusD Dialecticus

      Follow these steps to see the issue. Use Windows OS. Create new "Qt Widgets Application" project. Name it "Testing". Use CMAKE build system. Select "English (United States)" as language (I assume you have this language installed in the system). Use "Desktop Qt 6.6.1 MSVC2019 64bit" kit.

      In CMakeLists.txt file replace qt_create-translation with qt_add_translation. The code should look like this (if the project is named "Testing":

      #qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
      qt_add_translations(Testing
          TS_FILES ${TS_FILES}
          RESOURCE_PREFIX "i18n"
          LUPDATE_OPTIONS -locations none -no-ui-lines -no-obsolete
          LRELEASE_OPTIONS -idbased)
      add_dependencies(Testing Testing_lupdate)
      add_dependencies(Testing update_translations)
      

      Open MainWindow.ui. Go to menu Tools > Form Editor > Form Settings. In new dialog select check box ID-based. Close the .ui, and build the project. The first time you build the project the file Testing_en_US.ts should look like this:

      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE TS>
      <TS version="2.1" language="en_US">
      <context>
          <name>MainWindow</name>
          <message>
              <source>MainWindow</source>
              <translation type="unfinished"></translation>
          </message>
      </context>
      </TS>
      

      Open the .ui file again. windowTitle property now has id sub-property. Set id value to "id-title", and build the project again. The .ts file now looks like this:

      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE TS>
      <TS version="2.1" language="en_US">
      <context>
          <name>MainWindow</name>
          <message id="id-title">
              <source>MainWindow</source>
              <translation type="unfinished"></translation>
          </message>
      </context>
      </TS>
      

      A little bit confusing that there is a context, because ID based translation model should be contextless, but fine, whatever. BUT, now rebuild the project. The .ts file NOW looks like this:

      <?xml version="1.0" encoding="utf-8"?>
      <!DOCTYPE TS>
      <TS version="2.1" language="en_US">
      <context>
          <name></name>
          <message>
              <source>id-title</source>
              <translation type="unfinished"></translation>
          </message>
      </context>
      <context>
          <name>MainWindow</name>
          <message id="id-title">
              <source>MainWindow</source>
              <translation type="unfinished"></translation>
          </message>
      </context>
      </TS>
      

      Is this a bug, or am I doing something wrong? I don't expect two entries for the same translation term.

      This new entry is actually ignored by the code. Add translation to the <message id="id-title"> entry and it will appear in window title. Entry <source>id-title</source> is not used.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Due to your cmake commands, the lupdate is run before the ui file is converted to a ui_.h so the old source is used.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      DialecticusD 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Due to your cmake commands, the lupdate is run before the ui file is converted to a ui_.h so the old source is used.

        DialecticusD Offline
        DialecticusD Offline
        Dialecticus
        wrote on last edited by
        #3

        @Christian-Ehrlicher I'm not sure that's it. I commented out both add_dependencies lines, cleaned the project, deleted the Testing_en_US.ts file, executed cm update_translations, and then I get proper .ts file. I can execute this cm update_translations many times, nothing unusual happens. BUT once I build the project and run the cm command again I get the faulty .ts file again. I'm not exactly an expert on both CMAKE and Qt, so if there is a proper way to make it work I'd like to see it.

        I've found this bug report QTBUG-118808. It appears to be fixed in Qt 6.6.3. I'm using Qt Creator 12.0.2 (based on Qt 6.6.0). I guess I'll just have to wait for the next version of Qt Creator.

        Christian EhrlicherC 1 Reply Last reply
        0
        • DialecticusD Dialecticus

          @Christian-Ehrlicher I'm not sure that's it. I commented out both add_dependencies lines, cleaned the project, deleted the Testing_en_US.ts file, executed cm update_translations, and then I get proper .ts file. I can execute this cm update_translations many times, nothing unusual happens. BUT once I build the project and run the cm command again I get the faulty .ts file again. I'm not exactly an expert on both CMAKE and Qt, so if there is a proper way to make it work I'd like to see it.

          I've found this bug report QTBUG-118808. It appears to be fixed in Qt 6.6.3. I'm using Qt Creator 12.0.2 (based on Qt 6.6.0). I guess I'll just have to wait for the next version of Qt Creator.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Dialecticus said in ID based translation with CMAKE creates superfluous entries in TS file:

          It appears to be fixed in Qt 6.6.3. I'm using Qt Creator 12.0.2 (based on Qt 6.6.0). I guess I'll just have to wait for the next version of Qt Creator.

          I don't see what QtCreator has to do with the Qt version you're using for building your apps though.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          DialecticusD 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            @Dialecticus said in ID based translation with CMAKE creates superfluous entries in TS file:

            It appears to be fixed in Qt 6.6.3. I'm using Qt Creator 12.0.2 (based on Qt 6.6.0). I guess I'll just have to wait for the next version of Qt Creator.

            I don't see what QtCreator has to do with the Qt version you're using for building your apps though.

            DialecticusD Offline
            DialecticusD Offline
            Dialecticus
            wrote on last edited by
            #5

            I used Qt Maintenance Tool, and after 2 x 6.2 GB downloads (the first one ended abruptly while I wasn't watching), and some non-obvious-to-a-beginner hurdles to switch to new toolset, I fixed my problem. Qt 6.6.3 doesn't have the bug.

            1 Reply Last reply
            0
            • DialecticusD Dialecticus has marked this topic as solved on

            • Login

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