473,506 Members | 16,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

i18n and GUI under Windows

In short: I'm looking for a *simple* example of how to write a program
that can have its GUI in at least two languages under Windows ...
using only Python, of course!

I've downloaded Guido van Robot (great program!) so that my kids could
learn the basics of programming. Apparently it is set up to work in
French under *nix, but not under Windows. I've looked at the source
code, found where this is noted, scratched my head, looked at the web
to find solution, to no avail. GvR uses wxPython.

On the wxWidget website, it is said that there is a "internat" sample
program, that would seem to do what I'm looking for, but it doesn't
seem to be in the wxPython distribution.

I haven't found any simple demonstration with Tkinter either (or
Pythoncard, anygui, easygui, etc...). Sigh....

I *think* I understand the basics of unicode encoding (at the very
least, enough to have been able to modify Leo [another great program!]
to work properly on my machine [actually, it was well explained on the
web site]).

Any pointer, or sample program (like those found in useless Python)
demonstrating how this can be done would be appreciated. So, how do
you write a program that can display on a label (or menu item) either
"Guido" or "André" (Andre´) depending on the user's choice.
[Ok, that's not a good translation, but still :-)]

I am not a real programmer, just a hobbyist. However, if I can get
enough pointers to answer my question within the next week, I commit
myself to:
1) write a detailed tutorial in both French and English, explaining
how to do this in a way even I can understand :-)
2) find a way to modify GvR so that it works in languages other than
English on Windows.

Hey, I've already installed Poedit in anticipation of all the
translations I am going to do ;-)

André Roberge
Jul 18 '05 #1
7 1839
"Andr? Roberge" <an***********@ns.sympatico.ca> schrieb im Newsbeitrag

<snip/>

Have a look into the thread
http://groups.google.at/groups?hl=de...rl%24mde%241%4
0newshispeed.ch&rnum=1&prev=/groups%3Fq%3Di18n%2BGEIGER%26hl%3Dde%26lr%3D%26
ie%3DUTF-8%26selm%3Dcddprl%2524mde%25241%2540newshispeed.ch %26rnum%3D1

or google for "i18n GEIGER".

HTH

Cheers Franz GEIGER
Jul 18 '05 #2
Andr? Roberge wrote:
In short: I'm looking for a *simple* example of how to write a program
that can have its GUI in at least two languages under Windows ...
using only Python, of course!


I think the most simple approach is using a dictionary. Make one
Python file per language, and have that file contain only a single
dictionary named "translations". For keys, you have three options:

- use the English messages as keys (e.g. "Please enter your name")
- use short identifiers as keys (e.g. "EnterName")
- use numbers as keys (e.g. 116)

Regards,
Martin
Jul 18 '05 #3
Andr? Roberge <an***********@ns.sympatico.ca> pisze:
In short: I'm looking for a *simple* example of how to write a program
that can have its GUI in at least two languages under Windows ...
using only Python, of course!


http://wiki.wxpython.org/index.cgi/Internationalization

This applies to all Python programs, not only wxPython based. Just
follow instructions.

--
Jarek Zgoda
http://jpa.berlios.de/
Jul 18 '05 #4
an***********@ns.sympatico.ca (Andr? Roberge) said :
In short: I'm looking for a *simple* example of how to write a program
that can have its GUI in at least two languages under Windows ...
using only Python, of course!


Well, André, if you really want *simple* (as in *simplistic*, *simple-
minded* or *can't-get-no-simpler* :) I have something that does just that
(english/french under wxPython)... Note that most of the other
suggestions that were given in the rest of this thread are probably
better for "serious" work ; but going all the way to GNU gettext is a bit
involved, and quick-n-dirty hacks such as this can be enough for simple
apps and a handful of languages...

It goes something like this (purists please avert your eyes :-),
* at the beginning of the main module I have these statements :

#---------------------------------------------------------------------
# determine locale and set global french/english flag
# import localized strings and define gettext-like '_' function

import locale
lang, cp = locale.getdefaultlocale()
lang = lang[:2]
if not lang == 'fr' : lang = 'en'

import l10n

def _(msg) :
if lang == 'fr' :
return msg
else :
return l10n.trans[lang].get(msg, msg)
# if no translation found return the original (fr) string
* afterwards in your code, everywhere a string appears that needs to be
localized, wrap it in a _() function call (this is the convention set by
GNU gettext that everyone generally uses even if they don't use gettext
itself :)
i.e.: "André" becomes _("André")
* module l10n.py is just one big dictionary with language locales as
strings and dictionaries of original/translated strings as values, as in:

# MyApp localized strings
# -*- coding: iso-8859-1 -*-

trans = {}

trans['en'] = {
"André" : "Andrew",
"Bonjour" : "Hello",
"Dictateur Bienveillant A Vie" : "BDFL" }
* and that's it. You'll notice that in my example the original version is
in French and English is a translation. That's because it was grafted as
an afterthought/experiment onto already finished code. Forward-thinking
authors may want to do it the other way around, especially if they expect
to get help with other languages :-)

Then it's not too hard to add, say, a trans['de'] dict to l10n.py and
change the locale test above to use it. If automatic detection is not
adequate, then the GUI needs to provide a widget or dialog for the user
to set the desired language...

HTH,
fp

--
YAFAP : http://www.multimania.com/fredp/
Jul 18 '05 #5
Jarek Zgoda <jz****@gazeta.usun.pl> wrote in message news:<ch**********@nemesis.news.tpi.pl>...
Andr? Roberge <an***********@ns.sympatico.ca> pisze:
In short: I'm looking for a *simple* example of how to write a program
that can have its GUI in at least two languages under Windows ...
using only Python, of course!


http://wiki.wxpython.org/index.cgi/Internationalization

This applies to all Python programs, not only wxPython based. Just
follow instructions.


Thank you; I found it this morning after more googling. I think it
has all that I need. So now, all that is left is coding (and possibly
writing a tutorial - although the given reference is already very
good.)

Andre
Jul 18 '05 #6
Fred Pacquier <xn****@fredp.lautre.net> wrote in message news:<Xn***********************@212.27.42.76>...

Well, André, if you really want *simple* (as in *simplistic*, *simple-
minded* or *can't-get-no-simpler* :) I have something that does just that
(english/french under wxPython)... ...... Then it's not too hard to add, say, a trans['de'] dict to l10n.py and
change the locale test above to use it. If automatic detection is not
adequate, then the GUI needs to provide a widget or dialog for the user
to set the desired language...


Thanks for the suggestion. Actually I will NOT use the automatic
detection - and I would encourage others to do the same. The reason
is as follows:

Suppose that a French user is fairly fluent in Spanish, and very
little in English. Her computer's locale indicates that French should
be the default. The application she chose is available both with a
Spanish and an English interface - but not a French one. The
automatic detection scheme will chose English whereas, as she had
known it was available, she would have preferred to use the Spanish
one. But that can't be known by a program using the locale test.

Anyway, I'll try something along the lines of what is in the wxPython
wiki (suggested by another reader). Thanks to all those who helped.

André
Jul 18 '05 #7
an***********@ns.sympatico.ca (Andr? Roberge) said :
Thanks for the suggestion. Actually I will NOT use the automatic
detection - and I would encourage others to do the same. The reason
is as follows:


Quite, those are the sorts of reasons I had in mind when making that
remark. As I said, this was just a quick hack to verify things worked as
intended, not an end-user-friendly product :-)

--
YAFAP : http://www.multimania.com/fredp/
Jul 18 '05 #8

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

Similar topics

4
2024
by: ProgDario | last post by:
HI, I downloaded and installed the I18N pear package, but the link on the doc referring to the DB is broken. Where can I find the I18N DB? Without it I can't make it work! Thanks in...
3
1369
by: F. GEIGER | last post by:
Is there a way to do this in a professional manner? For now I only can think of having all strings in a file, read them into a dict at startup and then access them like so: print...
10
2956
by: Albretch | last post by:
.. Can you define the Character Set for particular tables instead of databases? . Which DBMSs would let you do that? . How do you store in a DBMS i18n'ed users' from input, coming over the web...
13
8626
by: Guido Wesdorp | last post by:
Hi! I've just released a JavaScript library to allow internationalizing JavaScript code and/or to do HTML translation from JavaScript. It's a first release, and it doesn't have all the features...
0
1242
by: Laszlo Zsolt Nagy | last post by:
Hello, I wonder if there is a standard for making i18n in Python projects. I have several Python projects that are internationalized. I also have Python packages with i18n. But it is still not...
3
1613
by: Darren Davison | last post by:
Hi, I have a documentation tool based on Java and XSLT that I want to add i18n capability to. There are around 8 stylesheets that process a Source generated by the Java code and some of the...
0
1085
by: i18n-bounces | last post by:
Your mail to 'I18n' with the subject Mail Delivery (failure i18n@mova.org) Is being held until the list moderator can review it for approval. The reason it is being held: Post by...
5
2021
by: adelhay | last post by:
Hello, I have a problem trying to internationalize a simple file in Python. the main folder is called "simple" here is the file: hello.py
2
3288
by: Norman Diamond | last post by:
My C# code is I18N'ed by appropriately naming and editing .resx files. At execution time, it works. My C++ code is somewhat I18N'ed. When I put UI code in C++ I use .rc files. When I link to a...
0
7105
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
7308
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
7371
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
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
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...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.