[PyQt] Translating from a function
Eric Frederich
eric.frederich at gmail.com
Wed Sep 29 21:39:44 BST 2010
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")
Thanks,
~Eric
On Wed, Sep 29, 2010 at 12:22 PM, Baz Walter <bazwal at ftml.net> wrote:
> On 29/09/10 15:19, Eric Frederich wrote:
>
>> I have a bunch of helper functions that raise exceptions and I'd like the
>> messages in those exceptions to be translated.
>> How should I get those strings translated?
>> QObject.tr is not a static method, I can't just call it.
>> I need a QObject don't I?
>>
>
> QCoreApplication has the static method "translate":
>
> http://doc.qt.nokia.com/4.6/qcoreapplication.html#translate
> _______________________________________________
> PyQt mailing list PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100929/72abf2df/attachment-0001.html>
More information about the PyQt
mailing list