I'm trying to translate my app in Qt but something goes wrong and there is no result

292 Views Asked by At

So I have made a *.qm file with translation done via QLinguist. Now I'm trying to translate program by clicking the button, but nothing happens.

it's files hierarchy

QTranslator translator;
void ChatWindow::on_actionRussian_triggered()
{
     translator.load(":/chApp_ru.qm");
     qApp->installTranslator(&translator);
     ui->retranslateUi(this);
}
1

There are 1 best solutions below

0
eyllanesc On BEST ANSWER

The problem is that you must place the path of the generated file, in your case Translations/chApp_ru.qm since this is a conversion of chApp_ru.ts, and the latter file takes as reference a relative path:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="ru_RU">
<context>
    <name>ChatWindow</name>
    <message>
        <location filename="../chatwindow.ui" line="14"/>
        <location filename="../chatwindow.ui" line="266"/>
        <source>chApp</source>
        <extracomment>by tia</extracomment>
        <translation></translation>
    </message>
[...]

I recommend adding to your qresource the .qm file that is in the translations folder.

Add it as shown in the figure:

enter image description here

And you have to modify your code to:

void ChatWindow::on_actionRussian_triggered()
{
     translator.load(":/Translations/chApp_ru.qm");
     qApp->installTranslator(&translator);
     ui->retranslateUi(this);
}

Output:

enter image description here