pygettext examples?

Joseph Santaniello joseph at
Fri Nov 30 18:30:01 CET 2001

Hi Martin,

I've gotten my code marked up: (

import gettext

def _(msg):
        return gettext.dgettext("test", msg)

def do_stuff()
        print _("I don't know.")

if __name__ == '__main__':

I've run and it made a messages.pot file that I translated:

msgid "I don't know."
msgstr "Jeg vet ikke."

And I ran msgfmt -o messages.pot

And runs successfully, but prints:

I don't know.

Shouldn't it print "Jeg vet ikke." ?

And when I want to use multiple languages, how does the .mo file identify 
itself as being for a particular language?

I see the stuff in the gettext docs on for installing 
languages, but how do I tell it what's what?



On 30 Nov 2001 at 13:48, Martin von Loewis wrote:

> Joseph Santaniello <joseph at> writes:
> > Does anyone have a link or some info on how in practical terms to use the 
> > pygettext module? I've looked at the online docs, and they do a good job 
> > of explaining in theory how to add multiple languages to an app, but they 
> > haven't got me to where I need to be... I need some examples and recipes 
> > to be able to figure it out.
> I think mailman uses gettext these days.
> I'd really recommend that you start using it, and ask any questions
> that you have in the process. Here are the rough steps:
> 1. Import or assign _ in your module, e.g. by doing
>    import gettext
>    def _(msg):
>      return gettext.dgettext("demoapp",msg)
> 2. Mark-up all messages with _
> 3. Extract the message catalog
> 4. Translate it
> 5. Compile the translations
> 6. Run the application
> If any of these steps, if executed in this order, gives problems,
> don't hesitate to ask for further details.
> Regards,
> Martin

More information about the Python-list mailing list