Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Translation of QDialogButtonBox in statically build app
QtWS25 Last Chance

Translation of QDialogButtonBox in statically build app

Scheduled Pinned Locked Moved General and Desktop
qt5translationstatic build
6 Posts 2 Posters 2.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
    Radim
    wrote on 23 Sept 2015, 15:40 last edited by
    #1

    Hi,
    I created an app that is statically build into one exe file. I use the translation .qm files to switch between languages. I load them from the qrc resource file:

    QApplication a(argc, argv);
    QTranslator translator;
    QString locale;
    locale = QLocale::system().name();
    translator.load(QString(":/lang/myapp_") + locale);
    a.installTranslator(&translator);
    

    My problem is that the "OK" and "Cancel" buttons of QDialogButtonBox are not translated.
    How to instruct the QT5.5 to include the system .qm files in the exe? I would like to avoid copying the system .qm files into my project.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 23 Sept 2015, 20:41 last edited by
      #2

      Hi and welcome to devnet,

      AFAIK, you can't avoid that copy

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      R 1 Reply Last reply 24 Sept 2015, 05:53
      0
      • S SGaist
        23 Sept 2015, 20:41

        Hi and welcome to devnet,

        AFAIK, you can't avoid that copy

        R Offline
        R Offline
        Radim
        wrote on 24 Sept 2015, 05:53 last edited by Radim
        #3

        @SGaist Thanks.
        If I cannot avoid a copy, can I at least automate the copy to my project via the .pro file by running qmake? Eg. are the translation files across platforms always at the same location?
        In addition, do I also need to load the translations manually from the resource file or is there another way to instruct the qt to load them from the resource file?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Radim
          wrote on 24 Sept 2015, 18:42 last edited by
          #4

          Another question related to translations. If I run lrelease myapp.pro, it generates the .qm file in the same directory as the .ts files. Is there a way to specify the output directory?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 24 Sept 2015, 20:00 last edited by
            #5

            IIRC, you can call lrelease myapp.pro -qm path/qmfile.qm

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Radim
              wrote on 25 Sept 2015, 07:45 last edited by Radim
              #6

              Finally I'm able to automatically copy the qt translation files and create resource file from the pro file:

              TRANSLATIONS = myapp_cs.ts \
                             myapp_xx.ts
              
              QT_TRANSLATIONS = qtbase_cs.qm
              
              #-------------------------------------------------
              # create lang folder
              QM_DIR = $$shadowed($${PWD})/lang
              mkpath($${QM_DIR})
              mkpath($${QM_DIR}/lang)
              
              #-------------------------------------------------
              # copy system translation files to lang folder
              for(FILE,QT_TRANSLATIONS){
                  FILE = $$shell_path($$[QT_INSTALL_TRANSLATIONS]/$${FILE})
                  system($${QMAKE_COPY} $${FILE} $$shell_path($${QM_DIR}/lang))
              }
              
              #-------------------------------------------------
              #generate qm files directly from qmake
              for(FILE,TRANSLATIONS){
                  QM_FILE = $$shell_path($${QM_DIR}/lang/$$replace(FILE,.ts,.qm))
                  system(lrelease $${FILE} -qm $${QM_FILE})
              }
              
              #-------------------------------------------------
              #create resource file with translations
              win32:system(cd $$shell_path($${QM_DIR}) & rcc --project -o lang.qrc)
              unix:system(cd $$shell_path($${QM_DIR}) ; rcc --project -o lang.qrc)
              
              RESOURCES += $${QM_DIR}/lang.qrc
              
              #-------------------------------------------------
              # extra target to generate ts translation files
              lupdate.commands     = lupdate $$_PRO_FILE_
              lupdate.depends      = FORCE
              QMAKE_EXTRA_TARGETS += lupdate
              
              #-------------------------------------------------
              # extra compiler to generate qm translation files
              lrelease.input         = TRANSLATIONS
              lrelease.output        = $${QM_DIR}/lang/${QMAKE_FILE_BASE}.qm
              lrelease.commands      = lrelease ${QMAKE_FILE_NAME} -qm ${QMAKE_FILE_OUT}
              lrelease.CONFIG       += no_link target_predeps
              QMAKE_EXTRA_COMPILERS += lrelease
              
              1 Reply Last reply
              0

              5/6

              24 Sept 2015, 20:00

              • Login

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