diff options
author | Nick Ratelle <nratelle@qnx.com> | 2012-01-17 23:05:54 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-12 06:54:42 (GMT) |
commit | 25c4ce6deef20c69d00fe1197a60e8b7587c81cb (patch) | |
tree | 4ab2fdd19e5313db6e37951ea703af5885007d40 /src/corelib | |
parent | 5a7619a459bce4fe0011044e7a1a2cff1297f800 (diff) | |
download | Qt-25c4ce6deef20c69d00fe1197a60e8b7587c81cb.zip Qt-25c4ce6deef20c69d00fe1197a60e8b7587c81cb.tar.gz Qt-25c4ce6deef20c69d00fe1197a60e8b7587c81cb.tar.bz2 |
Support changing locales at runtime in QPA plugins.
Change-Id: Id65798b81db2fa9fb5b1d929e4a94103995c6707
Reviewed-by: Jørgen Lind <jorgen.lind@nokia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/tools/qlocale_unix.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/corelib/tools/qlocale_unix.cpp b/src/corelib/tools/qlocale_unix.cpp index 5839a80..dd99792 100644 --- a/src/corelib/tools/qlocale_unix.cpp +++ b/src/corelib/tools/qlocale_unix.cpp @@ -46,8 +46,28 @@ #include "qstringlist.h" #include "qvariant.h" +#if defined(Q_OS_QNX) +#include <unistd.h> +#endif + QT_BEGIN_NAMESPACE +static const char *getSystemLocale() +{ +#if defined(Q_OS_QNX) + static char buff[257]; + + memset(buff, 0, sizeof buff); + + if (confstr(_CS_LOCALE, buff, 257) > 0) + return buff; + else + return qgetenv("LC_ALL"); +#else + return qgetenv("LC_ALL"); +#endif +} + #ifndef QT_NO_SYSTEMLOCALE struct QSystemLocaleData { @@ -57,12 +77,18 @@ struct QSystemLocaleData ,lc_monetary(QLocale::C) ,lc_messages(QLocale::C) { - QByteArray all = qgetenv("LC_ALL"); + updateLocale(); + } + + void updateLocale() + { + QByteArray all = getSystemLocale(); QByteArray numeric = all.isEmpty() ? qgetenv("LC_NUMERIC") : all; QByteArray time = all.isEmpty() ? qgetenv("LC_TIME") : all; QByteArray monetary = all.isEmpty() ? qgetenv("LC_MONETARY") : all; lc_messages_var = all.isEmpty() ? qgetenv("LC_MESSAGES") : all; lc_measurement_var = all.isEmpty() ? qgetenv("LC_MEASUREMENT") : all; + QByteArray lang = qgetenv("LANG"); if (lang.isEmpty()) lang = QByteArray("C"); @@ -93,7 +119,9 @@ Q_GLOBAL_STATIC(QSystemLocaleData, qSystemLocaleData) #ifndef QT_NO_SYSTEMLOCALE QLocale QSystemLocale::fallbackLocale() const { - QByteArray lang = qgetenv("LC_ALL"); + + QByteArray lang = getSystemLocale(); + if (lang.isEmpty()) lang = qgetenv("LC_NUMERIC"); if (lang.isEmpty()) @@ -216,6 +244,9 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const return lc_messages.quoteString(in.value<QStringRef>(), QLocale::AlternateQuotation); case ListToSeparatedString: return lc_messages.createSeparatedList(in.value<QStringList>()); + case LocaleChanged: + d->updateLocale(); + break; default: break; } |