0

我在翻译 QActions 时遇到了一些问题
在翻译文件中有 FILETAB_* 字符串的翻译,
但在应用程序中没有使用这些翻译,例如,用户参见
FILETAB_OPEN_FILE。
有人能帮忙吗?

void Application::setLanguage(const QString& locale)
{
    // remove previous
    if (current)
    {
        removeTranslator(current);
    }
    current_locale=locale;
    // install new

    current = translators.value(locale, 0);
    if (current)
    {
        installTranslator(current);
    }
}
void MainWindow::changeEvent(QEvent *event)
{
 if (event->type()==QEvent::LanguageChange)
 {
    retranslateUi(this);
 }
 QMainWindow::changeEvent(event);
}
void MainWindow::setupFileTabel()
{
    fileTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
    fileTableWidget->setContextMenuPolicy(Qt::CustomContextMenu);
    setupFileTabelContextMenu();
}
void MainWindow::setupFileTabelContextMenu()
{
    fileTabMenu = new QMenu(fileTableWidget);
    openFile = new QAction(tr("FILETAB_OPEN_FILE"), fileTabMenu);
    QObject::connect(openFile, SIGNAL(triggered()), this, SLOT(OpenFileSelected()));
    fileTabMenu->addAction(openFile);
    openDir = new QAction(tr("FILETAB_OPEN_FOLDER"), this);
    QObject::connect(openDir, SIGNAL(triggered()), this, SLOT(OpenDirSelected()));
    fileTabMenu->addAction(openDir);
    fileTabMenu->addSeparator();
    priority = new QMenu(fileTabMenu);
    priority->setTitle(tr("FILETAB_PRIORITY"));
    lowPriority = new QAction(tr("FILETAB_PRIORITY_LOW"), fileTabMenu);
    lowPriority->setCheckable(true);
    QObject::connect(lowPriority, SIGNAL(triggered()), this, SLOT(setLowForCurrentFile()));
    priority->addAction(lowPriority);
    mediumPriority = new QAction(tr("FILETAB_PRIORITY_MEDIUM"), fileTabMenu);
    mediumPriority->setCheckable(true);
    QObject::connect(mediumPriority, SIGNAL(triggered()), this, SLOT(setMediumForCurrentFile()));
    priority->addAction(mediumPriority);
    highPriority = new QAction(tr("FILETAB_PRIORITY_HIGH"), fileTabMenu);
    highPriority->setCheckable(true);
    QObject::connect(highPriority, SIGNAL(triggered()), this, SLOT(setHighForCurrentFile()));
    priority->addAction(highPriority);
    fileTabMenu->addMenu(priority);
    fileTabMenu->addSeparator();
    dontDownload = new QAction(tr("FILETAB_PRIORITY_ZERO"), fileTabMenu);
    dontDownload->setCheckable(true);
    QObject::connect(dontDownload, SIGNAL(triggered()), this, SLOT(setNotDownloadForCurrentFile()));
    fileTabMenu->addAction(dontDownload);
}
4

1 回答 1

0

QAction 的第一个参数不是动作的名称,而是将出现在该动作的菜单中的文本。tr() 函数将传入的字符串标记为应本地化的字符串。看看这里的解释。

http://qt-project.org/doc/qt-4.8/internationalization.html#use-tr-for-all-literal-text

于 2012-12-06T22:14:08.333 回答