1.到wxwidgets/locale找到zh_CN.po
2.到网上下载poedit工具,官网好像是www.poedit.net
3.用poedit打开zh_CN.po保存,程序会自动生成mo文件
4.把mo文件copy到你的代码的resource目录下的zh_CN目录下的my.po
5.修改myapp.h
C++代码
- class myApp : public wxApp
- {
- public:
- //初始化
- virtual bool OnInit();
- protected:
- wxLocale m_locale; // locale we'll be using
- };
6.修改myapp.cpp
C++代码
- #include "wx/log.h"
- bool myApp::OnInit()
- {
- //(*AppInitialize
- bool wxsOK = true;
- wxInitAllImageHandlers();
- if (m_locale.Init(wxLANGUAGE_CHINESE_SIMPLIFIED,
- wxLOCALE_CONV_ENCODING))
- {
- wxString resDir = wxT("resource");
- m_locale.AddCatalogLookupPathPrefix(resDir);
- m_locale.AddCatalog(wxT("my"));
- }
- if ( wxsOK )
- {
- myFrame* Frame = new myFrame(0);
- Frame->Show();
- Frame->ShowTip();
- SetTopWindow(Frame);
- }
- //*)
- //Frame->ShowTip();放在上面
- return wxsOK;
- }
到此汉化完成。
备注:关健代码解释
设置中文环境
m_locale.Init(wxLANGUAGE_CHINESE_SIMPLIFIED, wxLOCALE_CONV_ENCODING)
设置中文包mo文件所在目录,程序会在此目录下对应语言目录(zh_CN)下查找文件
wxString resDir = wxT("resource");
m_locale.AddCatalogLookupPathPrefix(resDir);
设置中文包mo的文件名,不带后缀
m_locale.AddCatalog(wxT("my"));
以上代码为非完整代码,不能直接运行。