因为是做测试的,所以
窗口里只有一个标签,如图
window.open('http://www.qtcn.org/bbs/attachment/Mon_1101/50_87144_c8048c3a17ace89.png?3');" style="max-width:700px;max-height:700px;" onload="if(is_ie6&&this.offsetWidth>700)this.width=700;" >然后,我生成了ts文件, testLocale_zh_CN.ts内容如下:
- <?xml version="1.0" encoding="utf-8"?>
- <!DOCTYPE TS>
- <TS version="2.0" language="zh_CN">
- <context>
- <name>MainWindow</name>
- <message>
- <location filename="mainwindow.ui" line="14"/>
- <source>MainWindow</source>
- <translation>主窗口</translation>
- </message>
- <message>
- <location filename="mainwindow.ui" line="27"/>
- <source>hello, world</source>
- <translation>你好,世界</translation>
- </message>
- </context>
- </TS>
然后用lrelease生成qm文件,main.cpp的代码如下:
- #include <QtGui/QApplication>
- #include <QTranslator>
- #include <QLocale>
- #include "mainwindow.h"
- int main(int argc, char *argv[])
- {
- QApplication a(argc, argv);
- //QString locale = QLocale::system().name();
- QTranslator translator;
- //translator.load(QString("testLocale_") + locale, ".");
- translator.load("testLocale_zh_CN.qm", ".");
- a.installTranslator(&translator);
- MainWindow w;
- #if defined(Q_WS_S60)
- w.showMaximized();
- #else
- w.show();
- #endif
- return a.exec();
- }
程序运行之后,还是英文的
没有变成中文=.=
pro文件代码testLocale.pro
- #-------------------------------------------------
- #
- # Project created by QtCreator 2011-01-11T17:53:16
- #
- #-------------------------------------------------
- QT += core gui
- TARGET = testLocale
- TEMPLATE = app
- SOURCES += main.cpp\
- mainwindow.cpp
- HEADERS += mainwindow.h
- TRANSLATIONS += testLocale_en.ts testLocale_zh_CN.ts
- FORMS += mainwindow.ui
- CONFIG += mobility
- MOBILITY =
- symbian {
- TARGET.UID3 = 0xe7826dd9
- # TARGET.CAPABILITY +=
- TARGET.EPOCSTACKSIZE = 0x14000
- TARGET.EPOCHEAPSIZE = 0x020000 0x800000
- }