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. Unable to load translations from resource file
Forum Updated to NodeBB v4.3 + New Features

Unable to load translations from resource file

Scheduled Pinned Locked Moved Solved General and Desktop
qtranslatorqt 5.6.0linux
9 Posts 3 Posters 4.0k Views 3 Watching
  • 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.
  • O Offline
    O Offline
    oberluz
    wrote on 4 Jun 2016, 16:53 last edited by
    #1

    Hi,

    I'm having trouble loading translationd from a .qrc file. Here is a miniml example to show the problem:

    #include <QApplication>
    #include <QTranslator>
    #include <QtDebug>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QTranslator translator;
        bool ok = translator.load(QLocale(), "Test", ".", ":/Translations");
        qDebug() << "Locale: " << QLocale::system().name() << (ok ? " ok" : " not ok");
    
        return a.exec();
    }
    

    The .pro file is:

    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = test
    TEMPLATE = app
    
    
    SOURCES += main.cpp
    
    HEADERS  +=
    
    FORMS    += mainwindow.ui
    
    RESOURCES += \
        translations.qrc
    

    translations.qrc contains a set of .qm files from a top level Traslations folder including Test.en_GB.qm yet when the progam runs it outputs:

    Locale: "en_GB" not ok

    What am I doing wrong?

    Thanks

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 4 Jun 2016, 21:00 last edited by
      #2

      Hi,

      Silly question but do you really have that Translations prefix in your .qrc file ? Can you share it ?

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

      O 1 Reply Last reply 4 Jun 2016, 21:19
      1
      • O Offline
        O Offline
        oberluz
        wrote on 4 Jun 2016, 21:17 last edited by
        #3

        Sure, no problem

        http://filebin.ca/2jXhIX5x1H6y/translations.qrc

        K 1 Reply Last reply 4 Jun 2016, 21:20
        0
        • S SGaist
          4 Jun 2016, 21:00

          Hi,

          Silly question but do you really have that Translations prefix in your .qrc file ? Can you share it ?

          O Offline
          O Offline
          oberluz
          wrote on 4 Jun 2016, 21:19 last edited by
          #4

          @SGaist The file reads as follows:

          <RCC>
          <qresource prefix="/Translations">
          <file>Translations/Test.qm</file>
          <file>Translations/Test.fr.qm</file>
          <file>Translations/Test.en.qm</file>
          <file>Translations/Test.de.qm</file>
          <file>Translations/Test.en_GB.qm</file>
          </qresource>
          </RCC>

          I've tried it with and without the Translations prefix and it fails in both

          1 Reply Last reply
          0
          • O oberluz
            4 Jun 2016, 21:17

            Sure, no problem

            http://filebin.ca/2jXhIX5x1H6y/translations.qrc

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 4 Jun 2016, 21:20 last edited by
            #5

            @oberluz
            If I read your qrc correctly, the path to the file(s) is: ":/Translations/Translations/Test.qm"

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            0
            • O Offline
              O Offline
              oberluz
              wrote on 4 Jun 2016, 21:25 last edited by
              #6

              translator.load(QLocale(), "Test", ".", ":/Translations/Translations"); also fails

              K 1 Reply Last reply 4 Jun 2016, 21:31
              0
              • O oberluz
                4 Jun 2016, 21:25

                translator.load(QLocale(), "Test", ".", ":/Translations/Translations"); also fails

                K Offline
                K Offline
                kshegunov
                Moderators
                wrote on 4 Jun 2016, 21:31 last edited by
                #7
                translator.load(QLocale(), "Test", QString(), ":/Translations/Translations");
                

                But in any case I'd first check if the file can be opened by that path, i.e.:

                QFile file(":/Translations/Translations/Test.qm");
                if (!file.open())
                    qDebug() << "Can't find it!";
                

                Read and abide by the Qt Code of Conduct

                O 1 Reply Last reply 4 Jun 2016, 22:00
                0
                • K kshegunov
                  4 Jun 2016, 21:31
                  translator.load(QLocale(), "Test", QString(), ":/Translations/Translations");
                  

                  But in any case I'd first check if the file can be opened by that path, i.e.:

                  QFile file(":/Translations/Translations/Test.qm");
                  if (!file.open())
                      qDebug() << "Can't find it!";
                  
                  O Offline
                  O Offline
                  oberluz
                  wrote on 4 Jun 2016, 22:00 last edited by
                  #8

                  @kshegunov Thank you, that did it!

                  K 1 Reply Last reply 4 Jun 2016, 22:02
                  0
                  • O oberluz
                    4 Jun 2016, 22:00

                    @kshegunov Thank you, that did it!

                    K Offline
                    K Offline
                    kshegunov
                    Moderators
                    wrote on 4 Jun 2016, 22:02 last edited by
                    #9

                    @oberluz
                    No problem, although the merit should go to @SGaist who actually sensed what the problem is. :)
                    Cheers!

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    0

                    1/9

                    4 Jun 2016, 16:53

                    • Login

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