Unable to load translations from resource file
-
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
-
Hi,
Silly question but do you really have that Translations prefix in your .qrc file ? Can you share it ?
-
Sure, no problem
-
@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
-
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!";