Results 1 to 3 of 3

Thread: tr() does not translate utf-8 literals

  1. #1
    Join Date
    Jun 2017
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default tr() does not translate utf-8 literals

    Dear programmers,

    in my Gui application (Qt version 4.8) I often use tr() to tanslate strings. It does work well with all string literals except those which contain utf-8 characters.

    For example, such a line is
    Qt Code:
    1. absChiSqrCheckBox = new QCheckBox(tr("\317\207\302\262 change <"));
    To copy to clipboard, switch view to plain text mode 
    So here we have the two utf-8 characters "χ²" (chi^2) encoded as octal C-characters.

    In my qmake project file I have
    Qt Code:
    1. CODECFORTR = UTF-8
    To copy to clipboard, switch view to plain text mode 

    And in main.cpp
    Qt Code:
    1. QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8"));
    To copy to clipboard, switch view to plain text mode 

    I run lupdate, then the linguist and release the qm files.

    So it seems I did exactly as is described in the Qt 4.8 documentation. I also tried trUtf8() instead of tr(), but this works neither. A string like the above is simply not translated.

    Many thanks for answers!

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: tr() does not translate utf-8 literals

    Hi, can you add a translation for them in linguist? Or did lupdate mess it up already?

    Ginsengelf

  3. #3
    Join Date
    Jun 2017
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: tr() does not translate utf-8 literals

    Hi, yes I could add the translation in the linguist. So, still I do not know the reason, but for the first release of my program I used a workaround:
    Qt Code:
    1. chiSqrString = QString("\317\207\302\262");
    2. absChiSqrCheckBox = new QCheckBox(QString(tr("%1 change <")).arg(chiSqrString));
    To copy to clipboard, switch view to plain text mode 
    thus avoiding a tr() on the utf string. Not so beautiful, but it's ok for the moment.

Similar Threads

  1. QT translate with ID
    By nmantelier in forum Qt Programming
    Replies: 2
    Last Post: 6th January 2017, 15:47
  2. Putting unicode in QString literals
    By reddish in forum Qt Programming
    Replies: 3
    Last Post: 30th October 2012, 02:25
  3. Translate my app (dynamic)
    By liran ritkop in forum Qt Programming
    Replies: 6
    Last Post: 31st March 2011, 11:25
  4. Replies: 8
    Last Post: 25th November 2010, 12:40
  5. translate on fly
    By Noxxik in forum Qt Programming
    Replies: 5
    Last Post: 26th February 2009, 15:21

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.