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. lupdate: Can we exclude individual source files from the .ts translation file?
Forum Update on Monday, May 27th 2025

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

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
4 Posts 2 Posters 1.5k 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 last edited by
    #1

    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?

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      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.

      (Z(:^

      R 1 Reply Last reply
      2
      • sierdzioS sierdzio

        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.

        R Offline
        R Offline
        Robert Hairgrove
        wrote on last edited by
        #3

        @sierdzio Thanks -- I like it!

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

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Robert Hairgrove
          wrote on last edited by Robert Hairgrove
          #4

          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.

          1 Reply Last reply
          1

          • Login

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