[wxPython-users] Re: Use another or native Language

Robin Dunn robin at alldunn.com
Mon Aug 14 18:58:05 PDT 2006


Franz Steinhäusler wrote:
> On Mon, 14 Aug 2006 10:18:42 -0700, Robin Dunn <robin at alldunn.com> wrote:
> 

>> _ is just a shortcut to a function (typically) and so you just need to 
>> give it a definition, or set it to some existing function.  For example:
>>
>>  >>> _ = wx.GetTranslation
>>  >>> lc = wx.Locale(wx.LANGUAGE_FRENCH)
>>  >>> _("Next")
>>  u'Suivant'
>>  >>> del lc
> 
> Hi Robin,
> 
> this del lc is obviously need, because without this the tranlation reverts 
> to the default language (english).
> 
> But why is this so, or the more important, how do I know, that I have to delete
> this instance and cannot rely on the garbage collector?

This is a tricky case.  The root of the problem is that the C++ wxLocale 
destructor resets the current locale to what was current when the 
wxLocale was constructed.  When you combine this with the Python 
reference counter/garbage collector then you end up with the following 
sequence of events when you do this:

lc = wx.Locale(wx.LANGUAGE_FRENCH)
lc = wx.Locale(wx.LANGUAGE_SPANISH)


1. the french wx.Locale is constructed, saving the current locale (None)

2. the locale is assigned to the new variable lc

3. the spanish locale is constructed, saving the current locale (French)

4. the locale is assigned to lc

5. the object formerly referenced by lc is garbage collected because its 
ref-count has dropped to zero

6. the C++ wxLocale destructor is called, and it restores the wxLocale 
that was current when it was created (None)


>> BTW, I think that on Windows it will not look in 
>> <prefix>/<lang>/LC_MESSAGES like it does on the other platforms, just 
>> <prefix>/<lang>.
> 
> No, it works for me, because my mo file is in
> c:\Eigene Dateien\python\drpython\locale\de\LC_MESSAGES\drpython.mo
> 
> and the four lines above cooperate with this directory.
> 
> But the same code works for:
> c:\Eigene Dateien\python\drpython\locale\de\drpython.mo
> 
> But if you think, the right location is this path, I'll put it here.

If it works then don't worry about it, I may have just misread or 
misremembered the code.

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





More information about the wxpython-users mailing list