views:

64

answers:

4

I'm trying to use translation files. I went through all the procedures: created ts file, translated it, but when I'm running the application again, it does not change.

I worked on the nokia example, just like in the instructions.

What could be my problem?

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QTranslator* translator=new QTranslator(0);

    if(QFile::exists("hellotr_la.qm"))
        qWarning("failed-no file");

    if(! translator->load("hellotr_la.qm"))
        qWarning("failed loading"); //the warning appears ****

    app.installTranslator(translator);
}
A: 

Hey,

Based on the example, can you simply try this :

 QTranslator translator;
 translator.load("hellotr_la");
 app.installTranslator(&translator);

Hope it will fix your problem !

Note 1 : No pointer here.
Note 2 : No extension in your filename.

Andy M
Your "Note 1" is irrelevant. In fact it may be a source of problems if the QTranslator object is not created in the main() method.
chalup
"Note 2" is irrelevant too. QTranslator::load will do all kinds of magic to locate an appropriate translation file. That includes disconsidering the suffix (by default, ".qm") when searching the file.
andref
@andref, allright, wasn't sure about it :)
Andy M
A: 

Basic steps of how to achieve localization in Qt is provided in this link

hope it would be helpful for you.

Shadow
+1  A: 

Where are the .qm files located? Your code is attempting to load the file from the current working directory, which can be anything during runtime. Specify a directory path in the call to QTranslator::load:

QTranslator* translator = new QTranslator();
if (translator->load("hellotr_la", "/path/to/folder/with/qm/files")) {
    app.installTranslator(translator);
}

Translations can be loaded from Qt resources, so it is a good idea to bundle them inside your executables. Then you would load them somewhat like this:

QTranslator* translator = new QTranslator();
if (translator->load("hellotr_la", ":/resources/translations")) {
    app.installTranslator(translator);
}
andref