i18n question

Hey all. I've started tackling i18n stuff with wxPython and would
like some clarification along the way. I checked the archive but I
couldn't find anything that quite addressed what I'm looking for. Here
are the issues I've encountered with my explorations:

1) I use Python's gettext to install the _() per the usual python
approach and translate all my strings before they are fed to the
widgets. However, the gettext.install function MUST be called within
the OnInit() function within my wxApp instance. It appears that
wxPython overwrites my _() function during the init. This is slightly
annoying since I had to move some static class stuff (that did need to
be translated when imported the module) to within class instances. Not
a big deal, but is this how it's supposed to work? Is this just a
wxWindows thing?

2) Now I need to initialize the wxLocale part of wxPython so it
displays translated wxPython widgets as well. It seems that wxPython
isn't very synched with the wxWindows at this point (I'm using
2.4.0.2). The Init function requires a locale name to select the
appropriate language: how do I extract that name? I tried looking into
the using the locale module but was unsure of a method that produced
consistent results (I tried setting my LC_ALL to various values to
experiment with the behavior). How have others solved this problem?

3) Am I doing this correctly? Is there a preferred way? This seems
like a good Wiki topic.

                 -- Mike

···

--
Michael Gilfix
mgilfix@eecs.tufts.edu

For my gpg public key:
http://www.eecs.tufts.edu/~mgilfix/contact.html

Michael Gilfix wrote:

  Hey all. I've started tackling i18n stuff with wxPython and would
like some clarification along the way. I checked the archive but I
couldn't find anything that quite addressed what I'm looking for. Here
are the issues I've encountered with my explorations:

1) I use Python's gettext to install the _() per the usual python
approach and translate all my strings before they are fed to the
widgets. However, the gettext.install function MUST be called within
the OnInit() function within my wxApp instance. It appears that
wxPython overwrites my _() function during the init. This is slightly
annoying since I had to move some static class stuff (that did need to
be translated when imported the module) to within class instances. Not
a big deal, but is this how it's supposed to work? Is this just a
wxWindows thing?

wxPython initialization doesn't do anything with Python's gettext, only a bit of tweaking with locale:

# wxGTK sets the locale when initialized. Doing this at the Python
# level should set it up to match what GTK is doing at the C level.
if wxPlatform == "__WXGTK__":
      try:
          import locale
          locale.setlocale(locale.LC_ALL, "")
      except:
          pass

# On MSW add the directory where the wxWindows catalogs were installed
# to the default catalog path.
if wxPlatform == "__WXMSW__":
      import os
      localedir = os.path.join(os.path.split(__file__)[0], "locale")
      wxLocale_AddCatalogLookupPathPrefix(localedir)
      del os

2) Now I need to initialize the wxLocale part of wxPython so it
displays translated wxPython widgets as well. It seems that wxPython
isn't very synched with the wxWindows at this point (I'm using
2.4.0.2). The Init function requires a locale name to select the
appropriate language: how do I extract that name? I tried looking into
the using the locale module but was unsure of a method that produced
consistent results (I tried setting my LC_ALL to various values to
experiment with the behavior). How have others solved this problem?

You may want to update as I fixed the wxLocale::Init wrapper in 2.4.0.4
to be able to handle both of the overloaded function signtures. However
in versions prior to that you should be able to use the wxLocale
constructor to specify the language by the enum values:

  locale = wxLocale(wxLANGUAGE_DUTCH)

3) Am I doing this correctly? Is there a preferred way?

I have no idea as I am fairly weak when it comes to i18n issues. I am
still learning about them. Another possible approach would be to use
wxLocale for everything. Just put your catalogs somewhere that the
wxLocale will search for them and then assign _() to be wxGetTranslation.

This seems
like a good Wiki topic.

That would be greatly appreicated.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!