There is a Qt application, I would like to make it work in two languages ​​- Russian and English. Everything that seems to be necessary, I have already done - tr() for the text, the translation file in Linguist too.
At the moment I'm trying to call the translation like this

 QTranslator translator; translator.load("translation_"+QLocale::system().name()); qApp->installTranslator(&translator); 

However, nothing changes, everything is the same as in the source
What am I doing wrong? What needs to be changed?

    2 answers 2

    Good day!

    Your problem is that you are trying to use the wrong file for translation: you need to use the * .qm file - this is the file that is obtained after the work of Qt Linguist)

    Files with the .ts extension are only markup (in XML format) that Qt Linguist understands in order to generate the binary translation file itself .qm and the qm files are used by QTranslator )

    Actually nothing depends on the method of loading - you can download from a file on your hard disk, you can from resources - the way you like it more)

    Successes!

      The lifetime of the translator object should be no less than the time of using this language. Those. make it static, for example, or create it in a heap before first use

      • Before first use - is it in main.cpp after creating a QApplication object? - Sergey305
      • As an option - AlekseyOk
      • I did, but nothing has changed. I even specify the name of the translation file itself, nothing changes - Sergey305
      • Most likely does not find the translation file. Is he in resources? - AlekseyOk
      • I added it to the resources (I created the prefix /lang in the resources, I added translation_ru.ts ), now I’m calling the source code like this: translator.load(":/lang/translation_ru.ts"); . All the same, all the same. Could there be a problem in installTranslator itself? - Sergey305