Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Problems running lupdate from within Qt Creator

Problems running lupdate from within Qt Creator

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
6 Posts 2 Posters 1.3k Views
  • 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.
  • R Offline
    R Offline
    Robert Hairgrove
    wrote on 21 Jan 2023, 13:02 last edited by
    #1

    The lupdate tool apparently does not honor the -extensions command-line option when I try to separate the strings into two different *.ts files when running the tool from within Qt Creator. I am using Qt 5.15.5 with Qt Creator 5.0.3.

    Background: in the application I am creating, most of the strings marked for translation are kept in one *.ts file and compiled into an external *.qm file which is loaded at runtime. This is working OK, except that there are some (just a few) strings which need to be translated (error messages displayed in the main() function before any settings file is loaded), and this stub *.qm file should be embedded into the application resources.

    In previous versions of Qt, I was able to place the smaller embedded strings into two files which have the extension *.cxx. All of the other strings are in *.cpp files. In my *.pro file, there is a TRANSLATIONS section; in the Tools/Options/Environment/External Tools, I have entered this string under Linguist/Update translations (lupdate)/Arguments:

    -extensions 'ui,cpp' %{CurrentProject:FilePath}
    

    However, when running lupdate from within Qt Creator, it seems to ignore the fact that 'cxx' is removed from the extensions list, and all strings are dumped into the same *.ts file. If I run lupdate outside of Qt Creator, I can make it work as desired. Somehow, I suspect that Qt Creator is ignoring the -extensions argument?

    Here is the *.pro file of a small test project:

    QT += core gui widgets
    
    CONFIG += c++11
    
    SOURCES += \
        CppDialog.cpp \
        CxxDialog.cxx \  # should NOT be put into the *.ts file!
        main.cpp \
        MainWindow.cpp
    
    HEADERS += \
        CppDialog.hpp \
        CxxDialog.hpp \
        MainWindow.hpp
    
    FORMS += \
        MainWindow.ui
    
    TRANSLATIONS += \
        test_translations_de_DE.ts
    

    Attached is a screenshot of the resulting *.ts file open in linguist: translation_problem.png

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Robert Hairgrove
      wrote on 21 Jan 2023, 13:15 last edited by
      #2

      Also, I tried writing both -extensions 'ui,cpp' ... and -extensions ui,cpp ... (with and without single quotes), and the result is the same.

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Robert Hairgrove
        wrote on 21 Jan 2023, 16:33 last edited by Robert Hairgrove
        #3

        In the meantime, I have tried running this from the command line. It does the same thing when I use the *.pro file,, so it doesn't have anything to do with Qt Creator.

        The only reason I thought it was working before is because I specified the file extensions to use and not the project file.

        When I navigate to the directory containing the sources, this works:

        lupdate -extensions 'ui,cpp' . -ts test_translations_de_DE.ts
        

        Result:

        Scanning directory '.'...
        Updating 'test_translations_de_DE.ts'...
            Found 5 source text(s) (5 new and 0 already existing)
        

        Note that only 5 strings were inserted into the *.ts file...

        But this doesn't work:

        lupdate -extensions 'ui,cpp' test_translations.pro
        

        Result:

        Info: creating stash file xxxx/test_translations/.qmake.stash
        Updating 'test_translations_de_DE.ts'...
            Found 7 source text(s) (7 new and 0 already existing)
        
        1 Reply Last reply
        0
        • S Offline
          S Offline
          SimonSchroeder
          wrote on 23 Jan 2023, 08:38 last edited by
          #4

          I am not sure what the underlying problem is in your case. However, there is one thing I'd like to add: In our project running lupdate on the project file takes ours (I haven't bothered to wait for it to finish). Running it instead on the directory only takes a couple of seconds (less than a minute). So, IMHO it is not advisable to run lupdate on a project file once the project starts to get larger. If I remember correctly, doing it on the project file will also look for translations in 3rd party code (which in our case are in different directories than our own source code).

          R 1 Reply Last reply 23 Jan 2023, 09:52
          0
          • S SimonSchroeder
            23 Jan 2023, 08:38

            I am not sure what the underlying problem is in your case. However, there is one thing I'd like to add: In our project running lupdate on the project file takes ours (I haven't bothered to wait for it to finish). Running it instead on the directory only takes a couple of seconds (less than a minute). So, IMHO it is not advisable to run lupdate on a project file once the project starts to get larger. If I remember correctly, doing it on the project file will also look for translations in 3rd party code (which in our case are in different directories than our own source code).

            R Offline
            R Offline
            Robert Hairgrove
            wrote on 23 Jan 2023, 09:52 last edited by
            #5

            @SimonSchroeder Thanks for your suggestions. Yes, I have noticed that it takes a very long time to run lupdate from within the project, and also looking for translated strings in 3rd party libraries which I have added as source code to the project.

            I think from now on that I will handle translations only from the command line, or from custom scripts outside of the Qt Creator environment. It seems to be the only solution for splitting the translations as I have described above.

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Robert Hairgrove
              wrote on 29 Mar 2023, 11:07 last edited by
              #6

              In the meantime, I found the solution for me that works here:
              https://lists.qt-project.org/pipermail/interest/2017-December/028990.html

              I have the .cxx file in a separate folder called locale which I exclude (along with 3rd-party code) like this in the .pro file:

              lupdate_only {
                TR_EXCLUDE += \
                  ../3rd_party/* \
                  src/locale/*
              }
              

              At first, this didn't work until I realized that the /* after the folder name is important.

              Also, my lupdate finishes now in a second or two, as opposed to several minutes before. :)

              1 Reply Last reply
              2
              • R Robert Hairgrove has marked this topic as solved on 29 Mar 2023, 11:08

              • Login

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