[PyQt] Docs on how pylupdate4 finds strings?
Phil Thompson
phil at riverbankcomputing.com
Fri Aug 21 16:39:26 BST 2009
On Thu, 20 Aug 2009 18:28:26 -0500, Dave Peterson <dpeterson at enthought.com>
wrote:
> I'm having trouble getting pylupdate4 (version 4.5.1) to detect strings
> that need translation in my python files. And after numerous searches,
> I can't seem to find any docs explaining how the tool goes about finding
> strings that need translation, so I'm not even sure how to go about
> debugging things.
>
> Ideally, I'd like my project to have a util.py module containing a tr()
> function that I can then use throughout the rest of my code. This
> module might look something like:
>
> from PyQt4 import QtGui
> def tr(context, text):
> return QtGui.QApplication.translate(context, text, None,
> QtGui.QApplication.UnicodeUTF8)
>
> And then in any other project module I could simply do:
>
> from util import tr
> CONTEXT='MainMenu'
> menu1 = Menu(name=tr(CONTEXT, u'File'), ....)
> menu2 = Menu(name=tr(CONTEXT, u'View'), ....)
>
> etc.
>
> However, for the life of me, I can't get pylupdate4 to detect the
> strings 'File' and 'View'. I've even tried "inlining" by doing
> something like:
>
> menu1 = Menu(name=QtGui.QApplication.translate('MainMenu', u'File'),
> ...)
>
> but that doesn't work either.
>
>
> Can anyone offer advice or point me at some docs for how pylupdate4 does
> it's scanning?
pylupdate is a hack of lupdate so it's not too clever handling Python. I
think there are two problems...
Make sure the translatable text is the first argument to tr().
Don't use unicode strings (ie. drop the u).
Phil
More information about the PyQt
mailing list