3

我尝试为标准保存或打开对话框设置本地化,但除窗口标题外的所有内容仍为英文。

我使用相同版本的 Qt 4.7.4 和 KDE。

以下示例应用程序:

#include <QApplication>
#include <QFileDialog>
#include <QTranslator>
#include <QLibraryInfo>
#include <QDebug>

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

    QTranslator qTranslator;
    QString transPath=QLibraryInfo::location(QLibraryInfo::TranslationsPath);
    qTranslator.load("qt_ru",transPath);
    app.installTranslator(&qTranslator);

    qDebug() << transPath;

    QFileDialog fileDialog(0, 0/*default caption*/,
        QDir::currentPath(), "All files (*.*)");
    fileDialog.exec();

    return 0;
}

打印"/usr/share/qt4/translations"(翻译路径)和警告:

KGlobal::locale::Warning your global KLocale is being recreated with a valid main
component instead of a fake component, this usually means you tried to call i18n related
functions before your main component was created. You should not do that since it most
likely will not work

我还尝试了一些其他更受支持的语言,例如德语(qt_de)、法语(qt_fr)和波兰语,但结果是一样的:只有字幕受到影响。

但是,如果我在任何安装了 KDE 的应用程序中打开“保存”对话框,对话框中的所有文本都会以俄语显示,并且不会向控制台打印任何警告。我在 Kwrite、Firefox(它使用默认的 KDE 对话框)、Konsole 和 Kaffeine 中尝试了对话框。

从翻译的角度来看,上面的代码是否正确?也许还有另一种方法可以为我的应用设置本地化?为什么要翻译其他应用程序中的对话框?除了目录中提供的文件,他们是否使用其他翻译文件/usr/share/qt4/translations

4

1 回答 1

1

Priviet 你还有这个问题吗?此刻,我的解决方案是添加:

QFileDialog fileDialog(0, 0/*default caption*/,
    QDir::currentPath(), "All files (*.*)", QFileDialog::DontUseNativeDialog);

调用文件对话框。

然而,通过这种方式,对话框是 Qt-native 并且不尊重 KDE。

但我正在寻找解决方案 How to get KDE dialog in system language intead。

于 2012-10-28T15:42:33.503 回答