Problems running lupdate from within Qt Creator
-
The
lupdatetool apparently does not honor the-extensionscommand-line option when I try to separate the strings into two different*.tsfiles 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
*.tsfile and compiled into an external*.qmfile 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*.qmfile 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*.cppfiles. In my*.profile, there is aTRANSLATIONSsection; in theTools/Options/Environment/External Tools, I have entered this string underLinguist/Update translations (lupdate)/Arguments:-extensions 'ui,cpp' %{CurrentProject:FilePath}However, when running
lupdatefrom 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*.tsfile. If I runlupdateoutside of Qt Creator, I can make it work as desired. Somehow, I suspect that Qt Creator is ignoring the-extensionsargument?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.tsAttached is a screenshot of the resulting
*.tsfile open inlinguist:
-
Also, I tried writing both
-extensions 'ui,cpp' ...and-extensions ui,cpp ...(with and without single quotes), and the result is the same. -
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.tsResult:
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
*.tsfile...But this doesn't work:
lupdate -extensions 'ui,cpp' test_translations.proResult:
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) -
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).
@SimonSchroeder Thanks for your suggestions. Yes, I have noticed that it takes a very long time to run
lupdatefrom 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.
-
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
.cxxfile in a separate folder calledlocalewhich I exclude (along with 3rd-party code) like this in the.profile: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
lupdatefinishes now in a second or two, as opposed to several minutes before. :) -
R Robert Hairgrove has marked this topic as solved on