PDA

View Full Version : QLocale not retreiving language right



jfjf
5th February 2011, 08:11
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

language = QtCore.QLocale().sytem().name()
print language
appTranslator = QtCore.QTranslator()
if appTranslator.load("app_" + language, "./translations"):
app.installTranslator(appTranslator)


Am I doing something wrong? Did somebody have the same Problems? Here is my locale setting:

LANG=en_US.utf8
LANGUAGE=en_US:en
LC_CTYPE=en_US.utf8
LC_NUMERIC=de_DE.utf8
LC_TIME=de_DE.utf8
LC_COLLATE=de_DE.utf8
LC_MONETARY=de_DE.utf8
LC_MESSAGES=en_US.utf8
LC_PAPER=de_DE.utf8
LC_NAME=de_DE.utf8
LC_ADDRESS=de_DE.utf8
LC_TELEPHONE=de_DE.utf8
LC_MEASUREMENT=de_DE.utf8
LC_IDENTIFICATION=en_US.utf8
LC_ALL=
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:

import locale
language, encoding = locale.getdefaultlocale(['LANG', 'LC_ALL', 'LANGUAGE', 'LC_MESSAGES', 'LC_CTYPE' ])
I hope somebody can help. Thanks in advance!

tbscope
5th February 2011, 08:17
Well...


LC_NAME=de_DE.utf8

should be obvious?

jfjf
5th February 2011, 08:42
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)