Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[solved]Translation doesn't work.



  • I am using qsTr in my qml file, e.g.

    CollapsiblePanel.qml
    @Text { text: qsTr("Location"); font.pointSize: 15; color: "white"; anchors.centerIn: parent; }@

    in cpp file I am loading qm file
    @QTranslator tr;
    tr.load(QStringLiteral("debugWFG_ru"));
    qApp->installTranslator(&tr);@

    this is part of tr file:
    @<?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE TS>
    <TS version="2.0" language="ru_RU">
    <context>
    <name>CollapsiblePanel</name>
    <message>
    <location filename="qml/debugWFG/CollapsiblePanel.qml" line="85"/>
    <source>Location</source>
    <translation>Местоположение</translation>
    </message>
    <message>
    <location filename="qml/debugWFG/CollapsiblePanel.qml" line="106"/>
    <source>Source list</source>
    <translation>Список источников</translation>
    </message>
    <message>
    <location filename="qml/debugWFG/CollapsiblePanel.qml" line="127"/>
    <source>Add new source</source>
    <translation>Добавить источник</translation>
    </message>
    <message>
    <location filename="qml/debugWFG/CollapsiblePanel.qml" line="148"/>
    <source>Ranking management</source>
    <translation>Управление ранжировкой</translation>
    </message>
    <message>
    <location filename="qml/debugWFG/CollapsiblePanel.qml" line="169"/>
    <source>Extra settings</source>
    <translation>Дополнительные настройки</translation>
    </message>
    </context>
    <context>
    <name>MyLogic</name>
    <message>
    <location filename="qtquick2applicationviewer/mylogic.cpp" line="109"/>
    <source>New</source>
    <translation>Новое</translation>
    </message>
    </context>
    ....
    </TS>
    @

    due to this file I get debugWFG_ru.qm by lrelease (http://yadi.sk/d/G1VDUYhjBEhre)

    translation doesn't work. help please, what's wrong?

    p.s. whole project you can find here: http://yadi.sk/d/insf3sdRBEhtt


  • Lifetime Qt Champion

    Hi,

    Are you sure the file can be found ? Is it in your source directory ? If so and you are using shadow build, it won't find it. Copy the translation file next to your executable and try again.



  • Oops, thanks - I really forgot to put qm file next to the exe. But in general, initially I had problem with translation in another project - information about this problem is in the post above.



  • P.S.
    tr.load(QStringLiteral("CollapsiblePanel_ru.qm"));
    and
    qApp->installTranslator(&tr);
    return true


  • Lifetime Qt Champion

    Did you had a look at the "online internationalization qml example":http://qt-project.org/doc/qt-4.8/declarative-i18n.html ? There's also a link to a complete example that might interest you.

    Hope it helps



  • Yes, I've already seen it. But there is another project type and Qt version.
    I used these manuals:
    http://qt-project.org/doc/qt-5.0/qtlinguist/linguist-manager.html
    http://qt-project.org/doc/qt-5.0/qtlinguist/linguist-programmers.html
    It still doesn't work :(


  • Lifetime Qt Champion

    What do you mean by other project type and Qt version ?



  • I use Qt 5.1 and QtQuick2ApplicationViewer instead of QmlApplicationViewer

    But I've already tried to put my translation files(qm & ts) into subdirectory of the root QML file, as it said in article you posted. Unfortunately it didn't help



  • It turned out that it's not allowed to setMainQmlFile before installing QTranslator


Log in to reply