我有我的应用程序,除了wxTextEntryDialog对话框中包含的'OK'和'Cancel'之外,所有翻译工作都很完美。 如何正确翻译?即使wxMessageBox在使用OK和取消时工作正常,但wxTextEntryDialog似乎不会翻译成任何其他语言。
我在代码中使用以下代码段进行语言分配:
wxLocale m_locale; // locale we'll be using (this is defined in the header file of my app)
// Within the source
lang = wxLANGUAGE_CHINESE_SIMPLIFIED; // for e.g. could be any language
m_locale.Init(lang);
// normally this wouldn't be necessary as the catalog files would be found in the default locations, but when the program is not installed the
// catalogs are in the build directory where we wouldn't find them by default
wxLocale::AddCatalogLookupPathPrefix(wxT(LanguagePath));// add path of install
// Initialize the catalogs we'll be using
m_locale.AddCatalog(_("messages")); // .mo file generated by my application language specific .mo file
提前感谢您的帮助。
答案 0 :(得分:1)
您对Init()
的电话是否成功?您应该检查其返回值,它可能找不到wxstd.mo
,其中包含wxWidgets中使用的所有消息的翻译,因为您在设置查找路径之前调用它。你需要
wxstd.mo
。Init()
。答案 1 :(得分:0)
谢谢@VZ。为了洞察力。您的方法帮助我更好地调试我的应用程序,即通过检查返回值,我能够看到Init()
没有成功。有了这个,我能够进一步调查。此外,wxstd.mo
只是默认的.po生成.mo(未翻译,为什么我需要这个?)
解决方案:我必须添加wxWidgets转换文件,即.mo生成的目录文件来自<wxdir>/locale/
中包含的.po文件。我不得不将它们复制到与messages.mo
相同的目录中。因此,对于简体中文,工作代码看起来像这样。
wxLocale m_locale; // locale we'll be using (this is defined in the header file of my app)
// Within the source
lang = wxLANGUAGE_CHINESE_SIMPLIFIED; // for e.g. could be any language
wxLocale::AddCatalogLookupPathPrefix(wxT(LanguagePath));// add path of install
m_locale.Init(lang, wxLOCALE_CONV_ENCODING);
m_locale.AddCatalog(wxT("zh_CN")); // This is the .mo file I generated from the wxWidgets .po files
// Initialize the catalogs we'll be using
m_locale.AddCatalog(_("messages")); // .mo file generated by my application language specific .mo file
我没有为某个目的包含检查,因为我希望应用程序以英语运行,即使该语言不受支持但我确实用它进行调试