【问题标题】:Qt localization: loading the localizable stringQt 本地化:加载可本地化的字符串
【发布时间】:2017-09-23 20:40:41
【问题描述】:

我想在 Qt 应用程序中加载本地化字符串。为此,我遵循几个步骤。如果我错了,请纠正我。

注意:它适用于QString,但不适用于const char*

  1. 更新 pro 文件 翻译语言

  2. 使用 Qt 生成 .ts 并编辑 语言学家。使用生成.qm 文件 lupdate 和 lrelease。

  3. 从特定的 位置。

这是我的const char* 的样子:

const char* sayHello =  QT_TRANSLATE_NOOP("FriendlyConversation","hello");

LocalizationWithQT::LocalizationWithQT(QWidget *parent)
    : QMainWindow(parent)
{
 //ui.setupUi(this);
 QString str = tr("say hello");
 QPushButton *pushbutton = new QPushButton(tr(sayHello));
 setCentralWidget(pushbutton)

}

这是我加载 .qm 文件的方式:

QApplication a(argc, argv);

    QTranslator translator;
    bool val = translator.load("c:\\Data\\test\\hellotr_la");
    a.installTranslator(&translator);

    LocalizationWithQT w;
    w.showMaximized();
    return a.exec();

问题是,如果我为“sayhello”提供任何替代拉丁字符串,它根本不会加载。

我不知道错误在哪里。

【问题讨论】:

    标签: string qt localization qt4 character-encoding


    【解决方案1】:

    如果您使用tr(sayHellow),Qt 将在当前上下文(=LocalizationWithQT 类)中查找 sayHellow 翻译。

    你必须明确地给 Qt 文本上下文:

    QPushButton *pushbutton 
        = new QPushButton(qApp->translate("FriendlyConversation", sayHellow));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多