Problems running lupdate from within Qt Creator
-
wrote on 21 Jan 2023, 13:02 last edited by
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 themain()
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 aTRANSLATIONS
section; in theTools/Options/Environment/External Tools
, I have entered this string underLinguist/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 runlupdate
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 inlinguist
: -
wrote on 21 Jan 2023, 13:15 last edited by
Also, I tried writing both
-extensions 'ui,cpp' ...
and-extensions ui,cpp ...
(with and without single quotes), and the result is the same. -
wrote on 21 Jan 2023, 16:33 last edited by Robert Hairgrove
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)
-
wrote on 23 Jan 2023, 08:38 last edited by
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).
-
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).
wrote on 23 Jan 2023, 09:52 last edited by@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.
-
wrote on 29 Mar 2023, 11:07 last edited by
In the meantime, I found the solution for me that works here:
https://lists.qt-project.org/pipermail/interest/2017-December/028990.htmlI have the
.cxx
file in a separate folder calledlocale
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. :) -