[PyQt] i18n

Frédéric frederic.mantegazza at gbiloba.org
Wed Feb 11 16:28:04 GMT 2009


On mercredi 11 février 2009, Doug Bell wrote:

> > Are there some tips, for example, to bind the _() method I use with
> > gettext and PyGTK? Something to help me migrate my code without having
> > to modify it everywhere...
>
> Here's how I do it:
>
>     def translate(text, comment=''):
>         """Translation function that sets context to calling module's
>            filename"""
>         try:
>             frame = sys._getframe(1)
>             fileName = frame.f_code.co_filename
>         finally:
>             del frame
>         context = os.path.basename(os.path.splitext(fileName)[0])
>         return unicode(QtCore.QCoreApplication.translate(context, text,
>                                                          comment))
>
>     def markNoTranslate(text, comment=''):
>         """Mark text for translation without actually doing the
>            translation"""
>         return text
>
>     __builtin__._ = translate
>     __builtin__.N_ = markNoTranslate

Thanks!

What is the purpose of the N_() function?

Is this code still working when the application is frozen? I know there are 
some problems getting the module name in this case...

-- 
    Frédéric

    http://www.gbiloba.org



More information about the PyQt mailing list