- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我可以将翻译器安装为 myApp.installTranslator(&translator)
是否可以拥有多个翻译文件并从应用程序的不同部分加载它们?我该怎么做?
最佳答案
是的,可以。正如医生所说:
Adds the translation file translationFile to the list of translation files to be used for translations.
Multiple translation files can be installed. Translations are searched for in the reverse order in which they were installed, so the most recently installed translation file is searched first and the first translation file installed is searched last. The search stops as soon as a translation containing a matching string is found.
Installing or removing a QTranslator, or changing an installed QTranslator generates a LanguageChange event for the QCoreApplication instance. A QApplication instance will propagate the event to all toplevel windows, where a reimplementation of changeEvent can re-translate the user interface by passing user-visible strings via the tr() function to the respective property setters. User-interface classes generated by Qt Designer provide a retranslateUi() function that can be called.
The function returns true on success and false on failure.
您需要加载一些翻译文件,qApp
宏来获取 main()
函数外部的 QApplication
实例,并执行以下操作:
QTranslator translator;//somewhere
void MainWindow::on_someButton_clicked()
{
translator.load("://en.qm");
qApp->installTranslator( &translator );
ui->retranslateUi(this); //for Qt designer
}
您还可以通过以下方式删除翻译器:
void MainWindow::on_someButton_2_clicked()
{
qApp->removeTranslator(&translator);
ui->retranslateUi(this);
}
国际化是一个重要部分,因此我还可以建议下一个链接:
Writing Source Code for Translation
还有书籍:
Foundations of Qt Development (Expert's Voice in Open Source) 第10章
C++ GUI Programming with Qt 4 (2nd Edition) (Prentice Hall Open Source Software Development Series) 第18章
Qt4.8. Professionalnoe programmirovanie na C++ (Russian) 第 31 章(针对俄语使用者)
关于qt - 我可以加载多个 QTranslator 文件,每个文件用于我的应用程序的不同部分吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27619595/
您好,我遇到了与 Rik had here 相同的问题 给出的答案是他必须“在代码中搜索链接请求“ajax.php”。将“ajax.php”替换为ajax.php/?lang='.qtrans_get
#include #include #include #include #include int main(int argc, char* argv[]) { QTextCodec::setC
我的项目 qml 文件中有 qsTr() 函数。我还为此 qml 创建了一个翻译文件。在主程序中,我创建了一个 QDeclarativeView 对象来运行 qml 文件,还有一个 QTranslat
我注意到 Qt 文档在翻译的某些方面不是很冗长。我一直在玩弄它,试图通过反复试验来弄清楚他们的行为。最终目标是在运行时更改翻译,但我很困惑 QTranslator 对象在多大程度上可以重用。 考虑一下
我网站的默认语言是俄语。检测浏览器语言已打开 当浏览器指定的 En 语言的用户访问我的网站首页 http://ivangrigoryev.com 时它会自动将他重定向到/?lang=en。 但是当用户
我有一个网站,我必须修改我的小部件才能使用 qTranslate 插件。有人可以指出我正确的方向吗? 基本上,我希望为每种语言显示我的输入字段,以便用户轻松知道在哪里输入信息,而不是在神秘的刺中输入信
有一个可用的应用程序,我正在为 GUI 添加一种新语言。一切正常,但应用程序的某些部分根本没有翻译。 QLinguist 检测到所有这些,我添加了新的翻译,但仍然没有结果。 这是没有得到翻译的代码片段
我正面临一个 wordpress 网站的问题,该客户想要为每种语言设置自定义字体系列 我正在使用 wordpress 的 Qtranslate 插件来翻译内容,我成功地做到了这一点……我还使用了一个名
Qt lupdate 和 QTranslator 将源字符串分组到独占上下文中。这意味着在一个上下文中定义的翻译将无法在不同的上下文中访问。 C++ 中的默认上下文是已覆盖的类的名称 QObject:
当我创建一个新页面并翻译它时,效果很好。 但是,如果我尝试翻译在安装此插件之前创建的现有页面,它会重定向或显示主页。 这是我的调试信息 http://pastebin.com/YqZ4CzAm 最佳答
我使用 qTranslate for Wordpress 来发布英语、瑞典语和德语的博客文章。我已激活“检测浏览器语言”,以便访问者将被转发到其浏览器指定语言的正确 URL。 因此,如果我访问 blo
我正在使用 wordpress 的“qtranslate”插件在我的网站中使用元语言, 我如何创建一个仅显示其中标志的组合? 我尝试使用以下代码生成下拉列表,但它只显示列表中的标志: echo qtr
我在 Wordpress 网站上使用 qTranslate,但在某些情况下,将其中的一些内容应用到 Wordpress 函数中时遇到了一些麻烦。例如,当我想在查询中包含“阅读更多链接”时,我可以这样做
我的客户在她的网站上使用了 qtranslate 插件,但它被它的创建者遗弃了,现在已经过时了。 我删除了它,并清理了我的数据库(用这个 https://gist.github.com/frnhr/4
我正在创建 Wordpress 多语言网站并为此使用 qTranslate 插件。为了插入内容,每种语言在 Wordpress TinyMCE 编辑器中都有自己的可视化/HTML 输入字段。问题是编辑
我在使用 QTranslator 加载翻译文件时遇到问题,因为它有一个语言环境修饰符。我使用的代码是, from PyQt4 import QtCore, QtGui from locale impo
我的 wordpress 中有自定义帖子类型“soto_property”和 URL 为“/edit.php?post_type=soto_property&page=properties.php”的
我正在尝试获取由 Ajax 调用加载的每种语言的正确内容(我在 Wordpress 环境中使用 qtranslate 插件)。 每次,内容仅以默认语言显示。 我正在考虑将 default-langua
设置=>语言中的“隐藏不适用于所选语言的内容”的设置。 未选中。这是整个网站的首选状态,但对于某些帖子,我想仅显示所选语言的最新帖子。 (因此,没有默认行为:“抱歉,此条目仅提供法语版本。”)。 到目
我可以将翻译器安装为 myApp.installTranslator(&translator) 是否可以拥有多个翻译文件并从应用程序的不同部分加载它们?我该怎么做? 最佳答案 是的,可以。正如医生所说
我是一名优秀的程序员,十分优秀!