wxPython-i18n: Using MDI, how to localize the Windows menu

I've written a wxPython application using the MDI interface. I have
the whole application translated to four different languages besides
English. All the menu elements except the Windows menu in the MDI
application framework get translated.

I found these strings in the src/msw/mdi.cpp file, along with their
translations in e.g. the fr.po file. Thus, they are intended to be
localized and the translations exist.

However, I haven't a clue how to turn the native wxPython translations
on to enable this menu's items to get translated. Can anyone point me
to the correct method?

I've tried putting the translations in my own .po files, but that
doesn't work. I also tried putting the wxPython's fr.po (for example)
in my locale/fr/LC_MESSAGES directory with fr.po and another name I
found in the Makefile, but those techniques didn't work.

I'm sure it's something simple I'm overlooking, but I haven't seen it
yet in any documentation I've read.

Thanks!

You need to tell wx.Local where to find the language catalog. See wx.Local.AddCatalogLookupPathPrefix

···

On 9/3/10 3:35 PM, someonesdad1 wrote:

I've written a wxPython application using the MDI interface. I have
the whole application translated to four different languages besides
English. All the menu elements except the Windows menu in the MDI
application framework get translated.

I found these strings in the src/msw/mdi.cpp file, along with their
translations in e.g. the fr.po file. Thus, they are intended to be
localized and the translations exist.

However, I haven't a clue how to turn the native wxPython translations
on to enable this menu's items to get translated. Can anyone point me
to the correct method?

I've tried putting the translations in my own .po files, but that
doesn't work. I also tried putting the wxPython's fr.po (for example)
in my locale/fr/LC_MESSAGES directory with fr.po and another name I
found in the Makefile, but those techniques didn't work.

I'm sure it's something simple I'm overlooking, but I haven't seen it
yet in any documentation I've read.

--
Robin Dunn
Software Craftsman

Hi, Robin:

Thanks for the reply. I posted the message and went camping for the
weekend and returned to find my computer dead.

I have tried various permutations of the following:

## Make sure our current directory is where the app.py file is
appdir = GetAppDirectory()
os.chdir(appdir)
## Set up localization
locdir = os.path.join(appdir, "locale")
gettext.install(app_name, locdir, unicode=True)
wxl = wx.Locale() # **** New code
wxl.AddCatalogLookupPathPrefix(locdir) # **** New code

My application directory has a locale directory where I keep the .mo
files and all the localization stuff works. However, I still can't
get the Windows menu in the MDI interface code to have their menu
items translated. For example, I have copied the fr/LC_MESSAGES/
wxstd.mo file from the wx-2.8-msw-unicode/wx/locale/fr directory of my
wxPython installation to my app's locale directory, yet I have not
been able to get the Windows menu's elements to translate.

I know it's some niggling detail of call order or a tidbit that's left
out, but I'm stumped. Any more suggestions?

Hi, Robin:

Thanks for the reply. I posted the message and went camping for the
weekend and returned to find my computer dead.

I have tried various permutations of the following:

## Make sure our current directory is where the app.py file is
appdir = GetAppDirectory()
os.chdir(appdir)
## Set up localization
locdir = os.path.join(appdir, "locale")
gettext.install(app_name, locdir, unicode=True)
wxl = wx.Locale() # **** New code
wxl.AddCatalogLookupPathPrefix(locdir) # **** New code

It's a staticmethod so you don't need to create an instance to add the prefix:

  wx.Locale.AddCatalogLookupPathPrefix(locdir)

IIRC, I think you also need a call to AddCatalog to tell it to load the message catalog. It would normally find the wx catalog by default, but if you've changed the location it may need you to call AddCatlog after the prefix has been set:

  wxl = wx.Locale(wx.LANGUAGE_FRENCH)
  wxl.AddCatalog('wxstd')

And if you want to also use the wx i18n code for your own messages then you can use another AddCatalog to do that. Be sure that you hold on to the locale reference so it is not garbage collected and the locale/catalog info is not reset to the default.

The strings used for the Window menu are in the catalogs, you can double check that yourself with code like this:

  >>> import wx
  >>> l = wx.Locale(wx.LANGUAGE_FRENCH)
  >>> wx.GetTranslation("Tile &Horizontally")
  u'R\xe9partir &horizontalement'

If the menu still doesn't have the right strings then there is probably a bug in there somewhere. Please create a ticket for it at trac.wxwidgets.org

···

On 9/18/10 10:04 AM, someonesdad1 wrote:

--
Robin Dunn
Software Craftsman