Results 1 to 3 of 3

Thread: QLocale not retreiving language right

  1. #1
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Question QLocale not retreiving language right

    Hello Qt Community,

    I am rather new to Qt and starting to develop in pyQt.
    Works great so far and there is a lot of documentation out there,
    but I have a Problem with QLocale not getting the language on my
    system right. I have an English Ubuntu with some LC_* set to German.

    I am trying to do the following, but this always returns "de_DE", even though LANG, LANGUAGE and LC_CTYPE is set to en_US.utf8
    Qt Code:
    1. language = QtCore.QLocale().sytem().name()
    2. print language
    3. appTranslator = QtCore.QTranslator()
    4. if appTranslator.load("app_" + language, "./translations"):
    5. app.installTranslator(appTranslator)
    To copy to clipboard, switch view to plain text mode 

    Am I doing something wrong? Did somebody have the same Problems? Here is my locale setting:
    Qt Code:
    1. LANG=en_US.utf8
    2. LANGUAGE=en_US:en
    3. LC_CTYPE=en_US.utf8
    4. LC_NUMERIC=de_DE.utf8
    5. LC_TIME=de_DE.utf8
    6. LC_COLLATE=de_DE.utf8
    7. LC_MONETARY=de_DE.utf8
    8. LC_MESSAGES=en_US.utf8
    9. LC_PAPER=de_DE.utf8
    10. LC_NAME=de_DE.utf8
    11. LC_ADDRESS=de_DE.utf8
    12. LC_TELEPHONE=de_DE.utf8
    13. LC_MEASUREMENT=de_DE.utf8
    14. LC_IDENTIFICATION=en_US.utf8
    15. LC_ALL=
    To copy to clipboard, switch view to plain text mode 
    I am working on an Ubuntu 10.04 with pyqt version 4.7.2, libqtcore4 version 4.4.6

    For now, as a workaround, I am using functionality from the python standard libary locale. This works on my system, but I don't know about Windows or other systems yet:
    Qt Code:
    1. import locale
    2. language, encoding = locale.getdefaultlocale(['LANG', 'LC_ALL', 'LANGUAGE', 'LC_MESSAGES', 'LC_CTYPE' ])
    To copy to clipboard, switch view to plain text mode 
    I hope somebody can help. Thanks in advance!

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QLocale not retreiving language right

    Well...

    Qt Code:
    1. LC_NAME=de_DE.utf8
    To copy to clipboard, switch view to plain text mode 

    should be obvious?

  3. #3
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: QLocale not retreiving language right

    Thanks for the hint, but this is not working, I changed LC_NAME also to en_US.utf8 and still get "de_DE". I even set it in /etc/environment (not just with an export in the console) and rebooted.


    Added after 10 minutes:


    I found out why QLocale is returning "de_DE".
    QLocale only looks for LC_NUMERIC and ignores all other LC_*, LANG ...
    see also a reported bug http://bugreports.qt.nokia.com/browse/QTBUG-1313

    I also consider this a bug. Why should I not have an English system and format my numbers differently. So for now I am sticking with my workaround that uses locale from the python standard lib (see initial post)
    Last edited by jfjf; 5th February 2011 at 08:40.

Similar Threads

  1. Set QLocale local once or in every class?
    By homerun4711 in forum Newbie
    Replies: 1
    Last Post: 19th January 2011, 10:54
  2. How does QLocale::toString(double i, char f, int prec) round?
    By ChiliPalmer in forum Qt Programming
    Replies: 0
    Last Post: 10th August 2010, 11:16
  3. Currency Symbol/Sign with QLocale
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 5th June 2010, 23:52
  4. QLocale/Resource
    By coderbob in forum Newbie
    Replies: 4
    Last Post: 21st November 2007, 20:51
  5. QLocale confusion :(
    By gri in forum Qt Programming
    Replies: 6
    Last Post: 15th June 2007, 13:09

Tags for this Thread

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.