[PyQt] How does sip.setapi("QString", 2) work with translations?

Tobias Rzepka tobias.rzepka at googlemail.com
Sat Nov 27 22:21:30 GMT 2010


Hello Brett,

with sip.setapi("QString",2) you gets always an unicode string back, 
witch is a true python object. So there can't be any Qt methods any 
more. This is why your second example fails.
You have two solutions. The one you mentioned or since Python 2.6 the 
new unicode format method:

qApp.translate("test","Internationalize {0}").format(42)

or with named arguments:

qApp.translate("test","Internationalize {my_number}").format(my_number=42)

There are many other options for the format method described in the 
Python documentation.

Tobias

Brett Stottlemyer schrieb am 27.11.2010 21:27:
> Hi, all-
>
> I'd like to use  sip.setapi("QString",2), but I'm using internationalization
> as well and it is giving me some trouble.
>
> If I try:
>> qApp.translate("test","Internationalize")
> I get Unicode "Internationalize" as the result (as expected)
>
> When I try:
>> qApp.translate("test","Internationalize %1").arg("42")
> I get
> AttributeError: 'unicode' object has no attribute 'arg'.  I guess this is
> expected, too, but I was hoping Phil had done some magic to have it work as
> expected.
>
> Is there a way to get this to work using Qt style formatting?  Or do I need
> to convert everything to python-style, like this:
>> qApp.translate("test","Internationalize %d")%42
> Thanks,
> Brett


More information about the PyQt mailing list