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
QtWS: Super Early Bird Tickets Available!

Unable to load translations from resource file

Scheduled Pinned Locked Moved Solved General and Desktop
qtranslatorqt 5.6.0linux
9 Posts 3 Posters 3.8k 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.
  • O Offline
    O Offline
    oberluz
    wrote on 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
  • SGaistS Offline
    SGaistS Offline
    SGaist Lifetime Qt Champion
    wrote on 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
    1
  • O Offline
    O Offline
    oberluz
    wrote on last edited by
    #3

    Sure, no problem

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

    kshegunovK 1 Reply Last reply
    0
  • O Offline
    O Offline
    oberluz
    replied to SGaist on 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
  • kshegunovK Offline
    kshegunovK Offline
    kshegunov Moderators
    replied to oberluz on 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 last edited by
    #6

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

    kshegunovK 1 Reply Last reply
    0
  • kshegunovK Offline
    kshegunovK Offline
    kshegunov Moderators
    replied to oberluz on 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
    0
  • O Offline
    O Offline
    oberluz
    replied to kshegunov on last edited by
    #8

    @kshegunov Thank you, that did it!

    kshegunovK 1 Reply Last reply
    0
  • kshegunovK Offline
    kshegunovK Offline
    kshegunov Moderators
    replied to oberluz on 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

  • Login

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