PDA

View Full Version : How do I get QObject::tr("%n apple(s)", "", n) to work?



bmn
25th January 2012, 09:55
I'm expecting the following behavior:

QObject::tr("%n apple(s)", "", 0) == QString("0 apples")
QObject::tr("%n apple(s)", "", 1) == QString("1 apple")
QObject::tr("%n apple(s)", "", 2) == QString("2 apples")

What I get instead is

QObject::tr("%n apple(s)", "", 0) == QString("0 apple(s)")
QObject::tr("%n apple(s)", "", 1) == QString("1 apple(s)")
QObject::tr("%n apple(s)", "", 2) == QString("2 apple(s)")

I thought this would work out of the box for English, but apparently it doesn't. Do I have to provide an English translation for English?

Unfortunately, the word "tr" is too short for the forums' search function.

MarekR22
25th January 2012, 11:11
Yes you have to do translation for English if you want to handle plurals. See here: http://developer.qt.nokia.com/doc/qt-4.8/i18n-source-translation.html#handling-plurals

bmn
27th January 2012, 17:29
You're right, I didn't realize that they had a "No Translation" column. Thank you, Marek!