Re: how to use i18n?
leon breedt <[email protected]> Fri, 10 Sep 2004 00:05:15 +0100
| Newsgroups | gmane.comp.python.optik.user |
|---|---|
| Message-ID | <[email protected]> |
On Thu, Sep 09, 2004 at 08:11:48AM -0400, Greg Ward wrote:
> Perhaps the author of that patch, Leon J. Breedt, could help -- hence
> I'm cc'ing him on this message.
Hi Thorsten/Greg,
The internationalization does work, however, the gettext library needs
to know to look for "optik.mo". I don't think its a good idea for Optik
to implicitly set that up either, as you will most probably want to
change that to be "myapp.mo" when you add your own usage strings.
So, here is a sample snippet of how you tell gettext to look in the
appropriate file:
from optik import OptionParser
import gettext
gettext.textdomain('optik')
gettext.bindtextdomain('optik')
parser = OptionParser()
parser.add_option("-f", "--file", dest="filename",
help="write report to FILE", metavar="FILE")
parser.add_option("-q", "--quiet",
action="store_false", dest="verbose", default=True,
help="don't print status messages to stdout")
(options, args) = parser.parse_args()
When I run it on my machine after copying optik.mo to the system
locale directory, with the appropriate LANG variable, I get:
[ljb@guldarhil]:...ld/Optik-1.5a1 $ env LANG=de_DE python2.3 test.py --help
Aufruf: test.py [Optionen]
Optionen:
-h, --help Diesen Hilfetext zeigen und beenden.
-f FILE, --file=FILE write report to FILE
-q, --quiet don't print status messages to stdout
You'll notice the two English messages, which is why I think you'll
want to copy optik.de.po to myapp.de.po and change the text domain
you bind to, so you can add your custom messages.
Hope this helps!
Leon
-------------------------------------------------------
This SF.Net email is sponsored by: YOU BE THE JUDGE. Be one of 170
Project Admins to receive an Apple iPod Mini FREE for your judgement on
who ports your project to Linux PPC the best. Sponsored by IBM.
Deadline: Sept. 13. Go here: http://sf.net/ppc_contest.php