wx.Locale mystery

Hello,

I do something like the following,

import gettext
import wx

the_locale = wx.Locale(wx.LANGUAGE_***)
the_locale.AddCatalogLookupPathPrefix("path/to/gettext mo files/")
the_locale.AddCatalog("PROGRAM NAME") # Assuming locale files are named PROGRAM NAME.mo
language = gettext.translation("PROGRAM NAME", "path/to/locale files dir/",
                                                        ["Canonical Name (i.e. sv_SE)"],
                                                        fallback=True)
language.install()

Also be sure that the wxLocale object remains alive during the runtime of your program.

Regards,

Cody Precord

···

On Dec 20, 2007, at 5:12 AM, Donn Ingle wrote:

Hi again,
I'm going slightly mad. Here's the setup:

1. I have a .mo file in the right place and I know it works because the
normal Python gettext procedure is working.
2. I have installed the Swedish locale (don't ask me why :slight_smile: ) and I know it
works because of 1. (I also test with af_ZA.utf8)
3. Before I run the app I set [LANG=sv_SE.utf8]

* I'm on Kubuntu Gnu/Linux, Python 2.5, wxPython 2.8 unicode.

I am doing this (from the wiki):

langid = wx.LANGUAGE_DEFAULT # Assume it fetches from $LANG
localedir = "fontypython/locales"
langid = wx.LANGUAGE_SWEDISH # trying to force it
os.environ['LANG'] = "sv_SE.utf8" # force it again!
mylocale = wx.Locale( langid )
mylocale.AddCatalogLookupPathPrefix( localedir )
mylocale.AddCatalog( "wxgui" ) # it finds this file.
_ = wx.GetTranslation

# All these show that it has Swedish
print mylocale.GetCanonicalName()
print mylocale.GetLanguage()
print mylocale.GetLocale()
print mylocale.GetName()
# But this one will not work... :frowning:
print wx.GetTranslation("Some String")
print _("Some String") # Does not work either.

Also, to test things out, I run the wxPython demo under another LANG setting
and it does not seem to change. I'm pretty sure I have at least af_ZA.utf8
installed fully (Swedish may be broken). I was looking at the stock buttons
control, to see if the text labels would change language but they
steadfastly remain in English.

I am using a few stock buttons in the app and was relying on them 'just
working'.

I am sure I'm to blame, but it's such a minefield that I'm just lost.

Is there another module of wxPython I still need to install?
\d

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Hello,

I do something like the following,

I have just tried a 'mixture' of the two like that and it's still confusing.

If I mix the two and then remove the line:
_ = wx.GetTranslation
The app now responds to print _("stuff") but the stock buttons are still all
in English.
I don't think the wx.Locale stuff is doing anything at all - the gettext
stuff is just working via _

Also be sure that the wxLocale object remains alive during the
runtime of your program.

How could I check? And what kills it?

By stays alive I meant it should be kept somewhere where it doesn't get cleaned up (i.e created as a temporary object in function call somewhere) until the program is finished.

I usually create the Locale object inside of a main method:

def Main():
  app = wx.App()
  mylocale = wx.Locale(xxxx)
  ...
  app.MainLoop()

if __name__ == '__main__':
  Main()

The 'Main' function doesn't return until the MainLoop is finished so the 'mylocale' object doesn't get deleted until the program exits.

\d

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Regards,

Cody Precord

···

On Dec 20, 2007, at 6:07 AM, Donn Ingle wrote:

jonhattan wrote:

I do this in OnInit:

self.loc = wx.Locale(wx.LANGUAGE_SPANISH)

so the locale object is there untill the app is destroyed.

Okay - I have tested this and wx.Locale is definitely staying alive. So,
it's not that.

\d

Stefano Bartaletti wrote:

Try installing language-pack-gnome-xx where xx is the locale you want
('se' in your case?), I think this will do the trick.

You are THE man! :smiley: Thanks. I'll let users know about that too.

I tested this on the wxpython demo, not my app - because I still can't get
wx.Locale to function, but this is a big step forward.

\d