Important: Please read the Qt Code of Conduct -

lupdate: Can we exclude individual source files from the .ts translation file?

  • 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 .ts files from individual sources, by running lupdate/lconvert/lrelease on the command line.

    However, what I would like to do is to run lupdate normally from within Qt Creator (using a .pro file with the qmake build 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 *.qm files 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 .ts file 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 .ts files generated when I run lupdate from 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 qmake variable or include guard that I can use to accomplish this?

  • Moderators

    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 lupdate does not understand, for example "cppignore , .hignore.

    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 lupdate for your small stub project, you can specify -extensions cppignore,hignore and it will pick them up.

    It's definitely hacky and ugly, but it should work.

  • @sierdzio Thanks -- I like it!

    But for now, I will not mark this as "solved" in case someone else has a more orthodox solution.

  • 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 lupdate and 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 .cxx extension, and they should be built normally.

    When building the stub .ts file from the command line, I will include only the files with the .cxx extension.

    I will post the results here.

Log in to reply