We want to support localization of the static text (labels, button labels, etc) to Japanese and Chinese in wxpython. We want only static text within the GUI elements to be changed, hard coding of Japanese or Chinese characters in the label(static text field开发者_JAVA百科s) would do the work for us. Any help on how to pursue this would be helpful.
Thank you
see: wx.GetTranslation
http://wiki.wxpython.org/Internationalization
What I do, is use _ = wx.GetTranslation at the top of my scripts, and enclose any strings in _("My String")
I use this batch script: http://code.google.com/p/gui2exe/source/browse/trunk/scripts/gen_lang to run the mki18n.py script found on the wiki. It basically runs the "gettext" command over your source code, and picks out your strings to translate that match the _("") format.
You then add a message catalogue to wxPython:
self.locale = wx.Locale(wx.LANGUAGE_JAPANESE, wx.LOCALE_LOAD_DEFAULT)
langdir = os.path.join('path', 'to', 'locale', 'folder')
self.locale.AddCatalogLookupPathPrefix(langdir)
self.locale.AddCatalog("program-name")
Of course, you'll have to allow the user to choose their preferred language, and map the wx.LANGUAGE_* from that. e.g.
languages = ( (_("English"), wx.LANGUAGE_ENGLISH),
(_("English (United Kingdom)"), wx.LANGUAGE_ENGLISH_UK),
(_("Japanese"), wx.LANGUAGE_JAPANESE),
(_("Portuguese"), wx.LANGUAGE_PORTUGUESE),
(_("Dutch"), wx.LANGUAGE_DUTCH),
(_("German"), wx.LANGUAGE_GERMAN),
(_("Russian"), wx.LANGUAGE_RUSSIAN) )
self.locale = wx.Locale(languages[user.preference.language], wx.LOCALE_LOAD_DEFAULT)
精彩评论