473,660 Members | 2,426 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 1847
"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%3Di1 8n%2BGEIGER%26h l%3Dde%26lr%3D% 26
ie%3DUTF-8%26selm%3Dcddp rl%2524mde%2524 1%2540newshispe ed.ch%26rnum%3D 1

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 "translatio ns". 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***********@n s.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.getdefau ltlocale()
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.new s.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.l autre.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***********@n s.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
2032
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 advance. :)ario
3
1375
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 str(MyTextDict('e', "errorOnDbStore")) or print str(MyTextDict('f', MyTextDict._ErrorKey_ErrorOnDbStore))
10
2983
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 (basically from everywhere) store it and properly serve it back to users, . . .? . Can you point me to info on this? I would preferably use Java/JDBC drivers.
13
8645
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 I'm interested in (e.g. it doesn't support domains, although I don't think that's much of a problem in most JavaScript applications, and it uses a non-standard message catalog format, instead of .po files translations are stored in XML) but it's...
0
1254
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 clean to me what is the recommended way to do it. Currently, I use a module called 'localization.py' with this code: from i18n_domain import DOMAIN import gettext
3
1626
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 static labels across the stylesheets are the same. Ideally I'd like to import a set of variables into each template, and preferably based on an XSLT parameter (the locale) but this obviously doesn't work:
0
1094
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 non-member to a members-only list
5
2036
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
3301
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 third party's DLLs I get what they supplied. When I link to Microsoft's CRT and MFC, um... Well anyway, at execution time it seems to be working, except when a third party's DLL has a secret dependency. But what about the installer? A Visual...
0
8341
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8630
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7362
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4177
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
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 we have to send another system
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.