代码之家  ›  专栏  ›  技术社区  ›  Federico

wxTextEntryDialog的“确定”和“取消”转换

  •  0
  • Federico  · 技术社区  · 11 年前

    除了wxTextEntryDialog对话框中的“OK”和“Cancel”之外,我的应用程序的所有翻译都工作得很好。 我怎样才能正确地翻译这些? 使用“确定”和“取消”时,即使wxMessageBox也能正常工作,但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 
    

    提前感谢您的帮助。

    2 回复  |  直到 11 年前
        1
  •  1
  •   VZ.    11 年前

    你打电话给 Init() 达到目的你真的应该检查它的返回值,它可能找不到 wxstd.mo ,其中包含wxWidget中使用的所有消息的翻译,因为您在设置查找路径之前调用了它。你需要

    1. 确保 wxstd.mo 在目录路径中可用。
    2. 呼叫 初始化() 在设置此路径之后。
    3. 检查其返回值。
        2
  •  0
  •   Federico    11 年前

    谢谢@VZ。了解更多信息。您的方法帮助我更好地调试应用程序,即我能够看到 Init() 未通过检查返回值成功。有了这个,我可以进一步调查。此外 wxstd.mo 只是默认的.po生成的.mo(没有翻译,所以我为什么需要这个?)

    解决方案:我必须添加wxWidgets转换文件,即.mo生成的目录文件 <wxdir>/locale/ 。我必须将它们复制到与我的 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 
    

    我没有包含检查,因为我希望应用程序以英语运行,即使不支持该语言,但我确实使用它进行了调试