internationalisation/gettext - any sample (.MO) data available ?

R

Richard Shea

Hi - I'd like to try applying internationalisation techniques to get
an idea of how much extra work is involved.

As a first step I'm looking at the class based gettext. I just
wondered if anyone knew of some ready made .MO files I could use - I
don't care what the subject matter is I just want something realistic
to work with (I have tried googling but a search string with 'sample'
and 'file' pulls up an awful lot of unrelated stuff).

thanks

richard shea.
 
J

Jeff Epler

Hi - I'd like to try applying internationalisation techniques to get
an idea of how much extra work is involved.

As a first step I'm looking at the class based gettext. I just
wondered if anyone knew of some ready made .MO files I could use - I
don't care what the subject matter is I just want something realistic
to work with

I've heard that when the folks at Red Hat decided to add i18n to their
installer, they used a filter program to translate the existing
english-language prompts into "redneck". That way, english-speaking
developers could still use the software when testing the completeness of
the i18n work.

http://www.xent.com/FoRK-archive/jun98/0010.html

Perhaps you could do the same as a way to get your test data.

Jeff
 
P

P

Richard said:
Hi - I'd like to try applying internationalisation techniques to get
an idea of how much extra work is involved.

As a first step I'm looking at the class based gettext. I just
wondered if anyone knew of some ready made .MO files I could use - I
don't care what the subject matter is I just want something realistic
to work with (I have tried googling but a search string with 'sample'
and 'file' pulls up an awful lot of unrelated stuff).

You can use some of the existing system mo files
(assuming your on linux).
This gives an overview, including a method to
list the contents of a system mo file:
http://www.pixelbeat.org/docs/i18n.html

Pádraig.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Richard said:
As a first step I'm looking at the class based gettext. I just
wondered if anyone knew of some ready made .MO files I could use - I
don't care what the subject matter is I just want something realistic
to work with (I have tried googling but a search string with 'sample'
and 'file' pulls up an awful lot of unrelated stuff).

Here is the smallest example I can think of (actually, the smallest one
using Tk - one with pure text output could be smaller):

# Python
import gettext
gettext.install("demoapp", localedir=".", unicode=True)

import Tkinter
t=Tkinter.Label(text=_("Hello, World"))
t.pack()
b=Tkinter.Button(text=_("Close"), command=t.tk.quit)
b.pack()

t.tk.mainloop()

Save this as a.py, and invoke

# Shell Command Line
xgettext a.py

(use xgettext.py if you don't have xgettext)

This produces a file messages.po. Change this to read

# demoapp message file
#
msgid ""
msgstr ""
"Project-Id-Version: demoapp\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2004-01-25 21:50+0100\n"
"PO-Revision-Date: 2004-01-25 21:52+0100\n"
"Last-Translator: Martin v. Löwis <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=iso-8859-1\n"
"Content-Transfer-Encoding: 8bit\n"

#: a.py:5
msgid "Hello, World"
msgstr "Hallo, Welt"

#: a.py:7
msgid "Close"
msgstr "Ende"

and invoke

# Shell Command Line
msgfmt messages.po

(use msgfmt.py if you don't have msgfmt)

Save the resulting messages.mo as

../de/LC_MESSAGES/demoapp.mo

Set the LANG environment variable to de_DE.ISO-8859-1, and
invoke

# Shell Command Line
python a.py

and enjoy the German user interface :) If you have multiple
languages, hand messages.po to translators (calling it demoapp.po),
and compile each translation you get back from the translators.

Regards,
Martin
 
R

Richard Shea

Here is the smallest example I can think of (actually, the smallest one
using Tk - one with pure text output could be smaller):

Hi Martin - Thanks very much for your very comprehensive reply, I
appreciate it.
(Thanks also to Jeff/Pádraig for your suggestions)

[lots of very useful stuff snipped]

I've followed the instructions, I think, and everything appears to
gone as it should except that at the moment I am still gettting the
English interface. I'm going to have another go at this tomorrow but I
just wanted to thank you for your kind word on my behalf.

I also wanted to double-check a couple of things. I've got my a.py in
one directory and the python installation in another (that's just the
way I do stuff on this machine) when you said ...
Save the resulting messages.mo as

./de/LC_MESSAGES/demoapp.mo

.... I presumed that was relative to a.py not the python interpreter ?
Is that correct ? That is if I have C:\richardspythonsrc\a.py I should
have C:\richardspythonsrc\de\LC_MESSAGES\demoapp.mo ?

Also I'm working on a WIN32 machine so to achieve ...
Set the LANG environment variable to de_DE.ISO-8859-1, and
invoke

.... I put ...

import locale
locale.setlocale(locale.LC_ALL, 'german')

.... up at the top of a.py - is that what you would advise ?

Thanks once again for your help.

regards

richard.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Richard said:
I also wanted to double-check a couple of things. I've got my a.py in
one directory and the python installation in another (that's just the
way I do stuff on this machine) when you said ...

As a starting point, you should make sure it really finds the .mo file.
The example is constructed so that the directory containing a.py must
be the current directory.

On Unix, you can use strace to find out where it looks for the .mo file,
or you can add print messages to gettext.py.
... I presumed that was relative to a.py not the python interpreter ?
Is that correct ? That is if I have C:\richardspythonsrc\a.py I should
have C:\richardspythonsrc\de\LC_MESSAGES\demoapp.mo ?
Correct.

Also I'm working on a WIN32 machine so to achieve ...



... I put ...

import locale
locale.setlocale(locale.LC_ALL, 'german')

... up at the top of a.py - is that what you would advise ?

No. Set the LANG environment variable, using the SET command
of cmd.exe, or changing Properties of My Computer.

There are other ways to programmatically specify the desired
language, but invoking setlocale is none of them.

Regards,
Martin
 
R

Richard Shea

Hi Martin - Just wanted to let you know that I tried again using the
set lang=german and it all worked beautifully ! It's really quite
weird to see it happen even on a tiny example like this. Thanks very
much for your help I appreciate it very much.

regards

Richard Shea.
 
?

=?ISO-8859-1?Q?=22Martin_v=2E_L=F6wis=22?=

Richard said:
Hi Martin - Just wanted to let you know that I tried again using the
set lang=german and it all worked beautifully ! It's really quite
weird to see it happen even on a tiny example like this. Thanks very
much for your help I appreciate it very much.

You are welcome! I'm glad you got it working.

Martin
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top