Results 1 to 3 of 3

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

  1. #1
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

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

    I'm expecting the following behavior:
    Qt Code:
    1. QObject::tr("%n apple(s)", "", 0) == QString("0 apples")
    2. QObject::tr("%n apple(s)", "", 1) == QString("1 apple")
    3. QObject::tr("%n apple(s)", "", 2) == QString("2 apples")
    To copy to clipboard, switch view to plain text mode 

    What I get instead is
    Qt Code:
    1. QObject::tr("%n apple(s)", "", 0) == QString("0 apple(s)")
    2. QObject::tr("%n apple(s)", "", 1) == QString("1 apple(s)")
    3. QObject::tr("%n apple(s)", "", 2) == QString("2 apple(s)")
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How do I get QObject::tr("%n apple(s)", "", n) to work?

    Yes you have to do translation for English if you want to handle plurals. See here: http://developer.qt.nokia.com/doc/qt...ndling-plurals

  3. The following user says thank you to MarekR22 for this useful post:

    bmn (27th January 2012)

  4. #3
    Join Date
    May 2007
    Posts
    131
    Thanks
    17
    Thanked 4 Times in 2 Posts

    Default Re: How do I get QObject::tr("%n apple(s)", "", n) to work?

    You're right, I didn't realize that they had a "No Translation" column. Thank you, Marek!

Similar Threads

  1. Replies: 1
    Last Post: 7th April 2010, 21:46
  2. Replies: 3
    Last Post: 15th February 2010, 17:27
  3. Replies: 3
    Last Post: 8th July 2008, 19:37
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.