Using gettext for "translation" of original string

Alex Martelli aleax at aleax.it
Fri Mar 14 06:18:30 EST 2003


Alexander Skwar wrote:

> Hello.
> 
> I'd like to use gettext to translate my program to other languages.  I
> used pygettext.py to create a messages.pot file containing the to be
> translated strings.  I then copied this file to
> ./locale/en/LC_MESSAGES/xhc.po and translated the strings from the
> original German texts to English.  Next I ran msgfmt.py to "compile" a
> .mo file out of the .po file.
> 
> I'm now able to do:
> 
> t = gettext.translation(domain = 'xhc', localedir = 'locale', languages =
> ['en']) t.install()
> print _('Beenden')
> 
> This will print 'Exit'.
> 
> But what do I do, when I want the original, untranslated string?

If you want to change function _ to return its argument verbatim
you could just do:

def _(arg): return arg

and this will re-bind name _ to this "transparent" little function.
Seems the simplest approach to me.

> gettext.translation(languages = ['de']) or languages = ['C'] raises an
> exception:

If you want to do it with gettext.transation you should install a
"transparent" (each string translates to itself) xhc.po into directory
/locale/de/LC_MESSAGES/ .


Alex





More information about the Python-list mailing list