Updating locale on-the-fly

Hello all,

When using the wx.Locale and wx.GetTranslation, is there a way to update all GUI widgets with a newly-set locale? In my program I allow the user to change the language from a preferences dialog, but haven't figured out how to apply the locale to the current runtime - the new locale is used when the application is loaded next.

Any suggestions?

Regards,
Steven

···

--
Steven Sproat, BSc
http://www.whyteboard.org/

Hello all,

When using the wx.Locale and wx.GetTranslation, is there a
way to update
all GUI widgets with a newly-set locale? In my program I
allow the user
to change the language from a preferences dialog, but haven't figured
out how to apply the locale to the current runtime - the new
locale is
used when the application is loaded next.

Any suggestions?

I wrote a "ChangeLanguage()" method, which I call when the user selects a
different language in my app.

That method knows what dialogs are open in my app at any given time (usually
between 4 and 6 because of the needs of my program), changes the locale, and
calls a "ChangeLanguage()" method in each of the open dialogs. Each
dialog's ChangeLanguage() method just updates all the visible labels, which
because the locale has been changed, get changed to the correct language.

It was surprisingly straight forward, once I figured out a good way to track
whether certain of my dialogs were open when I needed to know. The only
thing it can't do is update the language of dialogs that come from the OS,
such as the File Dialog.

If it will help, you can see my source code at
Transana download | SourceForge.net. Start in the MenuWindow.py
module, looking at the OnOptionsLanguage() method, which implements the menu
calls for all of the supported languages. Then ControlObjectClass.py's
ChangeLanguages() method calls ChangeLanguages() in whatever modules it
needs to, including MenuWindow, so look for the ChangeLanguages() method to
see how I update my menu items.

Hope that helps.

David

cool, I'll give it a look over and see what I can deduce from it.
thanks

···

On 05/07/2011 21:04, David wrote:

Hello all,

When using the wx.Locale and wx.GetTranslation, is there a
way to update
all GUI widgets with a newly-set locale? In my program I
allow the user
to change the language from a preferences dialog, but haven't figured
out how to apply the locale to the current runtime - the new
locale is
used when the application is loaded next.

Any suggestions?

I wrote a "ChangeLanguage()" method, which I call when the user selects a
different language in my app.

That method knows what dialogs are open in my app at any given time (usually
between 4 and 6 because of the needs of my program), changes the locale, and
calls a "ChangeLanguage()" method in each of the open dialogs. Each
dialog's ChangeLanguage() method just updates all the visible labels, which
because the locale has been changed, get changed to the correct language.

It was surprisingly straight forward, once I figured out a good way to track
whether certain of my dialogs were open when I needed to know. The only
thing it can't do is update the language of dialogs that come from the OS,
such as the File Dialog.

If it will help, you can see my source code at
Transana download | SourceForge.net. Start in the MenuWindow.py
module, looking at the OnOptionsLanguage() method, which implements the menu
calls for all of the supported languages. Then ControlObjectClass.py's
ChangeLanguages() method calls ChangeLanguages() in whatever modules it
needs to, including MenuWindow, so look for the ChangeLanguages() method to
see how I update my menu items.

Hope that helps.

David

--
Steven Sproat, BSc
http://www.whyteboard.org/

Hello steven,

here some example for updating locale on-the-fly.

Tested with Python 2.6.6 and wxPython 2.8.12.0 unicode.

Works fine under Windows, Mac and linux ubuntu* (*with hack from Ianare Sevi).

A) original code source example (Werner F. Bruhin) :
http://groups.google.com/group/wxpython-users/browse_thread/thread/c6637fbf5ebb0391/77f5923d7efd4e78?lnk=gst&q=I18N#77f5923d7efd4e78

B) original code source example (Ianare Sevi) for linux hack :
See “Internationalization.htm” file.

Sorry for my english poor.

Good continuation for your excellent “Whiteboard” application.

Doc.rar (60 KB)

Example_1.rar (70.3 KB)

Example_2.rar (37.7 KB)

Internationalization.htm (95.1 KB)

ValidI18nCodes.htm (25.7 KB)