473,397 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

on-the-fly translation with gettext

Hi all,
I'm a complete beginner in python and in GUI designing, yet I'm writing
a GUI using python and Tkinter. I need it to be available both in french
and english, so I read the Fine Manual and gave a try to gettext.
So far, I've managed to translate my app with the following snippet:

| import gettext
| def install_lang (lang):
| try:
| t = gettext.translation(domain = 'mydomain', localedir = 'locale',
| languages = [lang])
| t.install()
| except IOError:
| import __builtin__
| __builtin__.__dict__['_'] = lambda x: x
When I issue an

install_lang('en')

at the beginning of my program, it is translated in english and,
conversely, an

install_lang('fr')

at the beginning makes it available in french.
However, I'd like to let the user show the language on-the-fly during
execution. Having read the Python Library Reference, sec. 21.1.3.3 (see
http://docs.python.org/lib/node740.html), I added a menu with two
radiobuttons and I merely set them up to call install_lang:

| app_lang = StringVar()
| app_lang.set('en')
| langmenu = Menu(root)
| langmenu.add_radiobutton(label = "English", variable = app_lang, value = 'en',
| command = lambda l = 'en': install_lang(l))
| langmenu.add_radiobutton(label = "French", variable = app_lang, value = 'fr',
| command = lambda l = 'fr': install_lang(l))
However, there is no magic. The language of the application remains
unchanged. If it was defined to be english at startup, so will it
remain. Conversely, it will stay in french if this was the language at
startup.
Does somebody has any idea of what I'm doing wrong, and how to fix it?

Thanks.

--
benjamin
Sep 16 '08 #1
2 2028
On Sep 16, 4:57*am, Benjamin Sigonneau <benja...@dromaludaire.info>
wrote:
Hi all,

I'm a complete beginner in python and in GUI designing, yet I'm writing
a GUI using python and Tkinter. *I need it to be available both in french
and english, so I read the Fine Manual and gave a try to gettext.

So far, I've managed to translate my app with the following snippet:

| import gettext
| def install_lang (lang):
| * * try:
| * * * * t = gettext.translation(domain = 'mydomain', localedir = 'locale',
| * * * * * * * * * * * * * * * * languages = [lang])
| * * * * t.install()
| * * except IOError:
| * * * * import __builtin__
| * * * * __builtin__.__dict__['_'] = lambda x: x

When I issue an

* * install_lang('en')

at the beginning of my program, it is translated in english and,
conversely, an

* * install_lang('fr')

at the beginning makes it available in french.

However, I'd like to let the user show the language on-the-fly during
execution. *Having read the Python Library Reference, sec. 21.1.3.3 (seehttp://docs.python.org/lib/node740.html), I added a menu with two
radiobuttons and I merely set them up to call install_lang:

| app_lang = StringVar()
| app_lang.set('en')
| langmenu = Menu(root)
| langmenu.add_radiobutton(label = "English", variable = app_lang, value = 'en',
| * * * * * * * * * * * * *command = lambda l= 'en': install_lang(l))
| langmenu.add_radiobutton(label = "French", variable = app_lang, value = 'fr',
| * * * * * * * * * * * * *command = lambda l= 'fr': install_lang(l))

However, there is no magic. *The language of the application remains
unchanged. *If it was defined to be english at startup, so will it
remain. *Conversely, it will stay in french if this was the language at
startup.

Does somebody has any idea of what I'm doing wrong, and how to fix it?

Thanks.

--
benjamin
Try moving another window across your application after you change
languages and see if it gets updated. Sometimes you need to refresh
the layout of your application to get it to work...at least, in
wxPython you do.

Mike
Sep 16 '08 #2
Mike Driscoll <ky******@gmail.comwrites:
On Sep 16, 4:57*am, Benjamin Sigonneau <benja...@dromaludaire.info>
wrote:
>Hi all,

I'm a complete beginner in python and in GUI designing, yet I'm writing
a GUI using python and Tkinter. *I need it to be available both in french
and english, so I read the Fine Manual and gave a try to gettext.
[...]
>However, I'd like to let the user show the language on-the-fly during
execution. *Having read the Python Library Reference, sec. 21.1.3.3
(seehttp://docs.python.org/lib/node740.html), I added a menu with two
radiobuttons and I merely set them up to call install_lang:

[...]
>However, there is no magic. *The language of the application remains
unchanged. *If it was defined to be english at startup, so will it
remain. *Conversely, it will stay in french if this was the language at
startup.

Try moving another window across your application after you change
languages and see if it gets updated. Sometimes you need to refresh
the layout of your application to get it to work...at least, in
wxPython you do.

I tried it, but unfortunately my problem remains. Anyway, thanks for
the advice.
--
benjamin
Sep 17 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Krasnichuk | last post by:
Hello every one, Does anyone know how to make php work on your computer? please reply I need help Chris
20
by: Chris Krasnichuk | last post by:
hello, Does anyone know how I make php work on "my" computer? I made a mistake in my last post so I fixed it here. Chris
2
by: Patricia | last post by:
I am a new Oracle user. I am trying to install Oracle 9i Personal Edition on Windows ME; however, I am getting the following error during the installation: Oracle Database Configuration Assistant...
57
by: Bing Wu | last post by:
Hi all, I am running a database containing large datasets: frames: 20 thousand rows, coordinates: 170 million row. The database has been implemented with: IBM DB2 v8.1
1
by: gndzkdr | last post by:
hi all, i m new on Sql and i have a project related to C# and Sql. i have to do a project which must work on LAN, and there must be only one database file on main computer(Server Computer) and...
7
by: SHC | last post by:
I'm in need of some javascript to load two pages into two seperate iframes which are on two seperate and different pages. Rather complicated I know (and easier done in one frameset), but caused...
8
by: PhongPham | last post by:
Hello, Info relate: OS : uclinux Platform : unix version 2.4.22 (or 2.4.26) Chip on board : ARM7 I want to get a python package on network to "make" in linux (Fedora core 1 or anything...
8
by: Lemune | last post by:
Hi, I'm developing window service application on C# 2005. The service is to read a new excel file on certain directory, and process it to database. The service work find on XP. But when I...
19
by: pmw | last post by:
Hi I've got a problem with my current application. I currently use Windows Vista with Visual Studio Express 2008. If I compile the application on Vista, it works fine on Vista, but it doesn't...
16
by: tvnaidu | last post by:
I have these two ON and OFF buttons html code below, based on condition I am displaying status on screen(I have mutliple lines for each LED), my row shifting when some displaying ON and some...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.