wxPython in a foreign language Windows

255 views
Skip to first unread message

Jorge Godoy

unread,
Nov 12, 2004, 4:55:51 PM11/12/04
to wxpytho...@lists.wxwindows.org

Hi.


I'm sorry if this is my fault, but I'm not an expert in Windows. :-)

While running my application on Linux + GTK2 with the Stock Buttons I
see internationalized buttons and dialogs. While running the same
application on Windows, the buttons appears in English, but the dialogs
in -- in my case, of course -- Brazilian Portuguese. Is there something
I should do to have stock buttons in Portuguese here? Is it a Windows
configuration, wxPython configuration, some bug?


Thanks in advance,
--
Godoy. <go...@ieee.org>


David Woods

unread,
Nov 12, 2004, 5:38:34 PM11/12/04
to wxPytho...@lists.wxwidgets.org
I'm no expert, but I have worked hard to get i18n down for my own
application. If I say anything wrong here, I hope the list will correct me.

There are three levels you have to deal with for i18n.

First, there is the language of your own program prompts. These you have
complete control over and can i11nize pretty easily. See
http://wiki.wxpython.org/index.cgi/RecipesI18n.

Second, there are the wxPython prompts. You need seperate code to make sure
they will be internationalized too. I can't recall an example of a window
where wxPython's language setting makes a difference, but I know there are
some. The Print Preview window might be an example.

Third, there is the operating system language. The OS supplies some system
dialog boxes, such as the File Open dialog. (These differ on different
platforms, with wxPython supplying the ones that some operating systems
don't supply.) These you can't do anything about programmatically.

In Transana, I also use MySQL, which adds in a fourth source of a language,
but I won't even go there.

Here's some code from Transana for setting the initial language for my
program, based on a Config setting, including code that detects what
languages are installed on the system. I've left the comments in, as they
are helpful I think:

# If no language has been specified, request an initial language
if TransanaGlobal.configData.language == '':
initialLanguage = self.GetLanguage(self)

if initialLanguage == ENGLISH_LABEL:
TransanaGlobal.configData.language = 'en'
elif initialLanguage == SPANISH_LABEL:
TransanaGlobal.configData.language = 'es'
elif initialLanguage == FRENCH_LABEL:
TransanaGlobal.configData.language = 'fr'

# Determine the Program Folder so we can auto-detect installed
languages
scriptdir, dummy = os.path.split(sys.argv[0])

# Okay, a few notes on Internationalization (i18n) are called for
here. It gets a little complicated.
#
# There is more than one way to skin a cat. There is the Python way
to internationalize, using "gettext",
# and there is the wxPython way to internationalize, using
wx.Locale. I've experimented with both, and
# they both seem to work. However, the Python way allows me to
change languages while Transana is running,
# while the wxPython way does not. (It used to, but now it raises
an exception.) On the other hand,
# the Python way does not affect strings provided by wxPython, while
the wxPython way does.
# (I have yet to identify any such strings on Windows, though I
think the wx.MessageDialog on Linux
# might be an example.) Some error messages are provided by
embedded MySQL, and the language for these
# messages cannot be changed once the DB in initialized. A further
wrinkle is that common dialogs that
# come from the OS rather than from Python or wxPython, such as the
File and Print Dialogs, don't respond
# to either method of i18n. They get their language setting from
the OS rather than the program.
#
# What I have chosen to do is to implement Transana's i18n using
gettext, doing it the Python way so that
# users will be able to change languages on the fly. In addition, I
set the wx.Locale at program start-up
# to the initial language selected by the user. In this case, when
a user uses the Language Menu to
# change languages, all of the prompts supplied by Transana should
reflect the change. However, prompts
# supplied by wxPython and by MySQL will not change until the user
restarts Transana. At the moment, I
# don't know what any of these prompts that a user would actually
see might be.

# Install gettext. Once this is done, all strings enclosed in "_()"
will automatically be translated.
gettext.install('Transana', 'locale', False)
# Define supported languages for Transana
self.presLan_en = gettext.translation('Transana', 'locale',
languages=['en']) # English
# Spanish
dir = os.path.join(scriptdir, 'locale', 'es', 'LC_MESSAGES',
'Transana.mo')
if os.path.exists(dir):
self.presLan_es = gettext.translation('Transana', 'locale',
languages=['es']) # Spanish
# French
dir = os.path.join(scriptdir, 'locale', 'fr', 'LC_MESSAGES',
'Transana.mo')
if os.path.exists(dir):
self.presLan_fr = gettext.translation('Transana', 'locale',
languages=['fr']) # French

# Install English as the initial language if no language has been
specified
if (TransanaGlobal.configData.language == '') or
(TransanaGlobal.configData.language == 'en'):
lang = wx.LANGUAGE_ENGLISH
self.presLan_en.install()
# Spanish
elif (TransanaGlobal.configData.language == 'es'):
lang = wx.LANGUAGE_SPANISH
self.presLan_es.install()
# French
elif (TransanaGlobal.configData.language == 'fr'):
lang = wx.LANGUAGE_FRENCH
self.presLan_fr.install()

# This provides localization for wxPython
self.locale = wx.Locale(lang, wx.LOCALE_LOAD_DEFAULT |
wx.LOCALE_CONV_ENCODING)

You can see that I ended up with a mixed model, using Python's gettext() to
implement Transana's i18n and wxPython's wx.Locale to implement wxPython's
i18n. If you use wx.Locale for your program's i18n too, you'll need a
little additional code, which I experimented with but commented out for
Transana:

# NOTE: I've commented out the next line as Transana's i18n will be
implemented using Python's
# "gettext" rather than wxPython's "wx.Locale".
# self.locale.AddCatalog("Transana")

Then, if the user elects to change languages while the program is running, I
do this:

# English
if event.GetId() == MenuSetup.MENU_OPTIONS_LANGUAGE_EN:
TransanaGlobal.configData.language = 'en'
self.presLan_en.install()

# Spanish
elif event.GetId() == MenuSetup.MENU_OPTIONS_LANGUAGE_ES:
TransanaGlobal.configData.language = 'es'
self.presLan_es.install()

# French
elif event.GetId() == MenuSetup.MENU_OPTIONS_LANGUAGE_FR:
TransanaGlobal.configData.language = 'fr'
self.presLan_fr.install()

else:
wx.MessageDialog(None, "Unknown Language", "Unknown
Language").ShowModal()

TransanaGlobal.configData.language = 'en'
self.presLan_en.install()


Dialogs.InfoDialog(None, _("Please note that some prompts cannot be
set to the new language until you restart Transana, and\nthat the language
of some prompts is determined by your operating system instead of
Transana.")).ShowModal()

self.ControlObject.ChangeLanguages()

ControlObject.ChangeLanguages() obviously replaces all of my on-screen
prompts. When the user changes languages in mid stream, they get mixed
results. However, the instances where people change languages on the fly
are, I expect, extremely rare. Some people use Transana to study and teach
languages, and there people tend to have a pretty good understanding of both
languages in question. The other use case I have is when I'm doing a
training where I don't speak the native language and have to switch the
prompts to English to be able to help someone because I'm a stupid American,
and the person I'm helping is always willing to help me with the prompts
that don't switch. 95% of the prompts switch with this approach.

I know, too much information on i18n. You asked a somewhat simpler
question. Still, I took the time to figure all of this out, and maybe
someone out there cares.

So there is a language setting somewhere in Windows (Settings > Control
Panel > Regional Options in English) where you specify the OS language.
That's what you have to change to get the stock buttons into Brazilian
Portuguese. Different platforms have different results for what comes from
the OS and what comes from wxPython.

Hope that helps.

David

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


Jorge Godoy

unread,
Nov 14, 2004, 11:56:17 PM11/14/04
to wxpytho...@lists.wxwindows.org
David Woods <dwo...@wcer.wisc.edu> writes:

> I'm no expert, but I have worked hard to get i18n down for my own
> application. If I say anything wrong here, I hope the list will correct me.

:-)

> There are three levels you have to deal with for i18n.

<snipping a very good explanation on how you got it working />

> I know, too much information on i18n. You asked a somewhat simpler
> question. Still, I took the time to figure all of this out, and maybe
> someone out there cares.

Actually it isn't too much. I just expected that it was more automatic
for builtin things.

I worked a lot with I18N and L10N here. :-) I even have programs in
wxPython with this kind of support that you implemented -- not with the
menus and etc. to change it on the fly, I admit... If it was C, I would
expect to do all that all the time, but with Python I thought it would
be different for stock buttons. Anyway, I've added some code like the
one you suggested to see if it works on Windows, but it didn't.

I hoped that since wxPython was providing the labels and images for the
buttons it also took care of checking the language settings and had it
set up for me.

> So there is a language setting somewhere in Windows (Settings > Control
> Panel > Regional Options in English) where you specify the OS language.
> That's what you have to change to get the stock buttons into Brazilian
> Portuguese. Different platforms have different results for what comes from
> the OS and what comes from wxPython.

This is correctly set up. All other applications except for wxPython
apps show the buttons in pt_BR. The problem also happens with the
demo.

I've tried adding the module 'locale' and also adding 'wx.Locale' calls
in the code but it didn't work. At the Linux box everything works
perfectly -- and I suspect that at Windows XP it is some configuration
that I need to do either on the system or in wxPython... -- without
anything being done: wxPython recognized the system locale and showed
the correct buttons.

Any other place where I might take a look at?


Thanks!
--
Godoy. <go...@ieee.org>


Robin Dunn

unread,
Nov 15, 2004, 6:17:37 PM11/15/04
to wxPytho...@lists.wxwidgets.org

It may be that the po files havn't been updated yet for those new
strings. Or perhaps there is a problem loading the wx message catalog...

For MSW the following is done when wx is imported. You may want to play
with it and see if some tweaks are needed to make it play right on
Windows. If there are changes needed then please let me know:

localedir = os.path.join(os.path.split(__file__)[0], "locale")
wx.Locale_AddCatalogLookupPathPrefix(localedir)

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


www.stani.be

unread,
Nov 16, 2004, 7:45:30 PM11/16/04
to wxPytho...@lists.wxwidgets.org
On Suse 9.1 the following error occurred with a SPE
user. Any idea why?
Thanks,
Stani
http://spe.pycs.net

>> import wx.gizmos as wx_gizmos
>> File
"/usr/lib/python2.3/site-packages/wx/gizmos.py", line
5, in ?
>> from wxPython import gizmos
>> File
"/usr/lib/python2.3/site-packages/wxPython/gizmos.py",
line 2, in ?
>> import gizmosc
>> ImportError:
/usr/lib/python2.3/site-packages/wxPython/gizmosc.so:
symbol

_ZN14wxTextCtrlBase8overflowEi, version WXGTK2_2.4 not
defined in file
libwx_gtk2-2.4.so.0 with link time reference



__________________________________
Do you Yahoo!?
Meet the all-new My Yahoo! - Try it today!
http://my.yahoo.com


Reply all
Reply to author
Forward
0 new messages