Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
lupdate: Can we exclude individual source files from the .ts translation file?
Robert Hairgrove last edited by
Using Qt Creator 4.12.2 and Qt 5.12.9 on Linux Ubuntu 18.04 and Windows 10...
This might be an unusual request ... of course, I know that there are several options for including additional files, or for generating
.tsfiles from individual sources, by running
lupdate/lconvert/lreleaseon the command line.
However, what I would like to do is to run
lupdatenormally from within Qt Creator (using a
.profile with the
qmakebuild system) but exclude two source files which are only used at program startup in the
main()function. I have generated a much smaller "stub" translation file from these two source files which is loaded from compiled resources based on the operating system's current locale. The user might choose to run the application in a different UI language, but this is stored in an external XML settings file. The translations for the application chosen by the user are stored in external
*.qmfiles which are loaded dynamically based on the settings in the XML file.
The stub translation is used to show any error messages which might arise BEFORE the XML file can be read, of if there were validation errors raised while loading the XML file(s).
The problem is, that the strings to be translated are placed in the
.tsfile as well, IOW they are duplicated since they have already been translated in the "stub" file. I do not want to have these translated more than once, so I need to prevent them from being added to the giant
.tsfiles generated when I run
lupdatefrom within Qt Creator (i.e. the "normal" way).
Short of removing the two source files from the project and running
lupdate, then adding them in again, is there any
qmakevariable or include guard that I can use to accomplish this?
I don't think there is an option for removing or ignoring files.
There is one simple workaround I see - but it is smelly ;-) Rename the files you want to exclude to some extension which
lupdatedoes not understand, for example "
Make sure it's something different than default:
-extensions <ext>[,<ext>]... Process files with the given extensions only. The extension list must be separated with commas, not with whitespace. Default: 'java,jui,ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx,js,qs,qml,qrc'.
Then you can process your main project normally, but when calling
lupdatefor your small stub project, you can specify
-extensions cppignore,hignoreand it will pick them up.
It's definitely hacky and ugly, but it should work.
Robert Hairgrove last edited by
@sierdzio Thanks -- I like it!
But for now, I will not mark this as "solved" in case someone else has a more orthodox solution.
Robert Hairgrove last edited by Robert Hairgrove
Building on the suggestion given by @sierdzio I will try adding the "-extensions" command to the built-in command in Qt Creator used to run
lupdateand remove the
"cxx"extension, but keep this in the build options. Then I should be able to rename the source files for the stub to have
.cxxextension, and they should be built normally.
When building the stub
.tsfile from the command line, I will include only the files with the
I will post the results here.