Globalization
Globalization is providing the architecture and writing code such that the software performs as expected in any of the targetted end user locales, and can be fully localized.
Areas where there are locale-specific behavior include text display, text entry and editing (input methods, text wrapping, word selection, etc.), locale-aware date/time/number formatting, sorting, and searching.
Being fully localizable means that all translatable text and locale-specific data is loaded at run-time from data that is separate from code. Text messages are properly constructed from localizable templates. Locale-specific behavior (e.g. address layouts) is controlled by localizable data.
A Trivial Example
Just to get into the spirit of things, let's look at some of the code in Chandler.py:
def main():
try:
message = "while trying to start."
[snip]
application = wxApplication(redirect=False, useBestVisual=True)
message = "and had to shut down."
application.MainLoop()
except Exception, exception:
type, value, stack = sys.exc_info()
formattedBacktrace = "".join (traceback.format_exception (type, value, stack))
message = "Chandler encountered an unexpected problem %s\n\n%s" % (message, formattedBacktrace)
logging.exception(message)
# @@@ 25Issue - Cannot create wxItems if the app failed to initialize
dialog = wx.MessageDialog(None, message, "Chandler", wx.OK | wx.ICON_INFORMATION)
[snip]
Some G11N issues with this code are:
-
message gets loaded (in three different places) with hard-coded, non-Unicode strings.
- The end-user message assumes concatenation will work (base message + reason)
- The end-user message is constructed by a printf template (the localizer can't re-order parameters, though in this case that's probably OK)
- The dialog is loaded with a hard-coded title (possibly OK, if app name isn't localizable)
Here's another one from Application.py:
class wxApplication (wx.App):
[snip]
def OnInit(self):
[snip]
splashBitmap = self.GetImage ("splash")
splash = wx.SplashScreen(splashBitmap,
wx.SPLASH_CENTRE_ON_SCREEN|wx.SPLASH_TIMEOUT,
6000, None, -1, wx.DefaultPosition,
wx.DefaultSize,
wx.SIMPLE_BORDER|wx.FRAME_NO_TASKBAR)
[snip]
def GetImage (self, name):
return wx.Image("application/images/" + name + ".png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()
This code is loading & displaying the splashscreen, but this
splash.png image contains text. So the
GetImage method should add the locale into the path or the file name, so that either you're loading
application/images/en_US/splash.png or
application/images/splash_enUS.png.
Python Issues
There's a first cut at discussing some of the issues with Python & Globalization at
PythonI18N.
Readying your system for G18N