By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,986 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,986 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Jul 18 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Mon, Feb 02, 2004 at 07:07:37PM -0800, Richard Shea wrote:
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

Jul 18 '05 #2

P: n/a
P
Richard Shea wrote:
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.

Jul 18 '05 #3

P: n/a
Richard Shea wrote:
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 <ma****@v.loewis.de>\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

Jul 18 '05 #4

P: n/a
> 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.
Jul 18 '05 #5

P: n/a
Richard Shea wrote:
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 ...
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 ?


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

Jul 18 '05 #6

P: n/a
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.
Jul 18 '05 #7

P: n/a
Richard Shea wrote:
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

Jul 18 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.