[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] Translating from a function
From:       "Hans-Peter Jansen" <hpj () urpla ! net>
Date:       2010-09-29 22:14:14
Message-ID: 201009300014.14798.hpj () urpla ! net
[Download RAW message or body]

On Wednesday 29 September 2010, 22:39:44 Eric Frederich wrote:
> After trying a bunch of different ways I finally got the translate
> function to work.
> I am now having a hard time trying to shorten it up.
>
> This ...
> QCoreApplication.translate("MyContext", "My String")
> ... is a bit much.
>
> Is there any way to shorten it?
>
> I forget where I have seen it, but I think other translation schemes will
> import the translator function as an underscore so you can have text like
> _("my String")
>
> Is there any way to shorten it?
> I run into problems with either pylupdate4 not picking it up, or into
> problems with linguist.
>
> If I do...
>
> from PyQt4.QtCore import QCoreApplication
> mytr = QCoreApplication.translate
>
> ... then pylupdate4 doesn't pick them up.
>
> If I try to do something like...
>
> from functools import partial
> translate = partial(QCoreApplication.translate, "MyContext")
>
> ... then linguist doesn't pick up the right context.
>
> Any help is appreciated.
> I do have it working now, but I don't like how long this is...
> QCoreApplication.translate("MyContext", "My String")

You can always define a helper method like this:

    def tr(self, msg, ctx = None, n = -1):
        return QtGui.QApplication.translate("YourForm", msg, ctx,
               QtGui.QApplication.UnicodeUTF8, n)

Unfortunately, with a module global helper function, which would get us en 
par with C++ at least on module level, all strings are collected in a 
context "@default":

def tr(msg, ctx = None, n = -1):
    return QtGui.QApplication.translate("YourForm", msg, ctx,
	   QtGui.QApplication.UnicodeUTF8,n)

pylupdate4 is written in python, hence these issues should be solvable..
I guess, Phil will happily take patches. I also noticed, that there are path 
related issues, if you work across subdirs, but I never got around looking 
into it (yet).

Pete
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic