km2442
km2442

Reputation: 827

Qt5 Loading .qm translation file

I'm trying to translate my Qt5.5 application to English. I made .ts file and translated strings -> made English.qm file. I've placed it in resources:

translations.qrc:

<RCC>
    <qresource prefix="/translations">
        <file>Resources/Languages/English.qm</file>
    </qresource>
</RCC>

When I'm trying to load it, I can't... Could you help me how to do it the right way to load .qm and replace orginal strings by translated from .qm? One additional question, how to load orginal strings when translation is loaded?

fragment of main.cpp file:

QtSingleApplication a(argc, argv);

QTranslator tra;
if (tra.load(":/translations/Resources/Languages/English.qm"))
{
    a.installTranslator(&tra);
}
else 
{
    qWarning() << "File not loaded"
}

I always get information "File not loaded".

Upvotes: 2

Views: 2690

Answers (1)

0rko
0rko

Reputation: 168

This should work, tried it myself:

<RCC>
    <qresource prefix="/translations">
        <file>resources/languages/english.qm</file>
    </qresource>
</RCC>

QApplication a(argc, argv);
QTranslator tra;
if (tra.load(":translations/resources/languages/english.qm")) {
    a.installTranslator(&tra);
    qDebug() << "File loaded";
} else {
    qWarning() << "File not loaded";
}
return a.exec();

RESOURCES += \
    resources.qrc

TRANSLATIONS += resources/languages/english.ts

Creation of the ts file: lupdate Test.pro

Creation of the qm file: lrealease Test.pro

Upvotes: 2

Related Questions