multilanguage application - step by step

M

miamia

Hello guys,

I would like to translate all strings in my application for several
languages (eng, es, de, etc) and user should be able to switch app
from one language to another. I am still newbie with python so is
there any "step-by-step" tutorial how to to this? thanks for help
 
C

Chris Rebert

Hello guys,

I would like to translate all strings in my application for several
languages (eng, es, de, etc) and user should be able to switch app
from one language to another. I am still newbie with python so is
there any "step-by-step" tutorial how to to this? thanks for help

Please refrain from double-posting in the future.

The `gettext` module's docs look fairly straightforward:
http://docs.python.org/library/gettext.html#internationalizing-your-programs-and-modules
See also the "Here’s an example of typical usage for this API:" code snippet.

For the translation file workflow, the Wikipedia article seems enlightening:
http://en.wikipedia.org/wiki/GNU_gettext

Cheers,
Chris
 
A

Andrew Berg

P.S. sorry for double posting but when I post my message on googlegroups I
can't see it in googlegroups (don't know why)
Last time I looked at this newsgroup (which was not that long ago) on
Google Groups, it was 2 days behind.
 
T

Thomas Jollans

I used gettext in xmm2tray. You can have a look at the code as an example:
http://code.jollybox.de/hg/xmms2tray/file/04443c59a7a1/src/xmms2tray/__init__.py

I tried this:
# -*- coding: utf-8 -*-
import gettext
gettext.bindtextdomain('multilanguage', 'E:\folder')
'\f' is, IIRC, the form feed character. Use forward slashes or escape
your backslashes properly.
gettext.textdomain('multilanguage')
_ = gettext.gettext
I specified the translation file location in the gettext.translation
call, but I'm no expert; I assume this'll work too.
# ...
lang1 = gettext.translation('multilanguage', languages=['sk'])
use fallback=True here if you want it to work without translation files
(simply using the string passed to _())
lang1.install()
print _('This is a translatable string.')
but ErrNo 2 no translation file found for domain: 'multilanguage'
I am doing something wrong way. I would like to switch languages in my
program 'on the fly' without affecting windows.
The usual way of using gettext is to use the system locale to determine
the right language. Of course, you can have different translations and
install() them (I expect), but you'll have to re-load all the strings
displayed in your application when you switch language, which might be
tricky.
 
T

Thomas Jollans

Hello Thomas,
thank you now it works and all my string are translated. But as you
said switching languages is small problem now. I am using pygtk and I
have no idea how to re-load all strings in my app when I click on
button with another language. Any idea?

Well, it depends on how you're constructing your interface. If you're
creating all the widgets in Python code, you could move all your
foo.text = "Bar"; statements to one method that updates the text for all
widgets, and call that both from the constructor and from the
language-switching event handler.

If you're using Glade, your only option might be to completely reload
the interface, but then you'd somehow have to save the user's data and
immediately restore it perfectly.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top