internationalisation/gettext - any sample (.MO) data available ?
"Martin v. Löwis"
martin at v.loewis.de
Tue Feb 3 13:30:38 EST 2004
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 <martin at 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
More information about the Python-list
mailing list