回复: 【提问】如何实现动态语言切换?
#6 [XChinux 01-18 13:45]
Qt的帮助里有例子的。实际上就是根据选择加载不同的翻译.qm文件进行翻译。
#7 [abdurahim 01-18 13:55]
thank you very much!!!
#8 [sinl 02-16 01:14]
我想这个是楼主想要的,不过是英文,哪位大虾做件功德无量的事情,把它翻译一下?
Dynamic Language Switching
For most applications, detecting the user's preferred language in main() and loading the
appropriate .qm files there is perfectly satisfactory. But there are some situations where users might need the ability to switch language dynamically. An application that is used continuously by different people in shifts may need to change language without having to be restarted. For example, applications used by call center operators, by simultaneous translators, and by computerized cash register operators often require this capability. Making an application able to switch language dynamically requires a little more work than loading a single translation at startup, but it is not difficult. Here's what must be done: .. Provide a means by which the user can switch language. .. For every widget or dialog, set all of its translatable strings in a separate function (often called retranslateStrings()) and call this function when the language changes. Let's review the relevant parts of a Call Center application's source code. The application provides a Language menu to allow the user to set the language at run-time. The default language is English.
Figure 15.1. The Call Center application's Language menu Since we don't know which language the user will want to use when the application is started, we no longer load translations in the main() function. Instead we will load them dynamically when they are needed, so all the code that we need to handle translations must go in the main window and dialog classes.
Let's have a look at the Call Center application's QMainWindow subclass:
MainWindow::MainWindow(QWidget *parent, const char *name)
: QMainWindow(parent, name)
{
journalView = new JournalView(this);
setCentralWidget(journalView);
qmPath = qApp->applicationDirPath() + "/translations";
appTranslator = new QTranslator(this);..
#9 [xuxinshao 03-03 21:30]
to:sinl
这篇文章是从那里找来的,能把地址告诉我吗?
#10 [sinl 03-21 16:23]
引用第9楼xuxinshao于2006-03-03 21:30发表的“”:
to:sinl
这篇文章是从那里找来的,能把地址告诉我吗?
没记错的话是《C++ GUI Programming with Qt 3》这里
Chapter 15. Internationalization