简体   繁体   English

qml对话框上的翻译按钮

[英]translate buttons on qml dialogs

I am using QML MessageDialog with a Cancel and a Yes button. 我正在使用带有“取消”和“是”按钮的QML MessageDialog My phone is set to german, but the Cancel and Yes button are not translated. 我的手机设置为德语,但是“取消”和“是”按钮未翻译。

I am following the qt documentation here and added this to my main: 我在这里关注qt文档并将其添加到我的主要文档中:

QTranslator qtTranslator;
qtTranslator.load("qt_" + QLocale::system().name(),
        QLibraryInfo::location(QLibraryInfo::TranslationsPath));
app.installTranslator(&qtTranslator);

It does not work. 这是行不通的。 This code: 这段代码:

qDebug() << QLibraryInfo::location(QLibraryInfo::TranslationsPath);
qDebug() << qtTranslator.isEmpty();

Tells me: 告诉我:

  1. The translation path is: /work/build/______________________________PADDING______________________________/translations 翻译路径为: /work/build/______________________________PADDING______________________________/translations

  2. The qtTranslator object is empty. qtTranslator对象为空。

I also load a translator for my own strings, and that works. 我还为自己的字符串加载了一个翻译器,并且可以正常工作。

So I do I properly initialize translation of Qt internal stings on android? 所以我可以在Android上正确初始化Qt内部字符串的翻译吗?

If you want translate your application you should distrubute qt translation files with it. 如果要翻译应用程序,则应使用它来分发qt翻译文件。 For android simple copy translation files to assets folder. 对于android简单将翻译文件复制到assets文件夹。 Then set this path for qtTranslator . 然后为qtTranslator设置此路径。

You can do this with qmake. 您可以使用qmake做到这一点。 Just put this to your .pro file: 只需将其放入您的.pro文件即可:

android {
    ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
    TRDESTDIR = $$system_path($$PWD/android/assets/translations)
    QMAKE_POST_LINK = $$QMAKE_COPY $$shell_path($$[QT_INSTALL_TRANSLATIONS]/qt*_ru.qm) $$TRDESTDIR
}

Of course you should change ANDROID_PACKAGE_SOURCE_DIR and TRDESTDIR to your actual location if it differs. 当然,如果不同,则应将ANDROID_PACKAGE_SOURCE_DIRTRDESTDIR更改为您的实际位置。 Also you should change qt*_ru.qm to your language. 另外,您应该将qt*_ru.qm更改为您的语言。

Then you could load translation like: 然后,您可以像这样加载翻译:

qtTranslator.load("qt_ru","assets:/translations")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM