From dd7c9ab007aad43e077b433197997ddc68f609b5 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sun, 20 Nov 2011 23:23:01 +0100 Subject: [PATCH] Workaround locale issue when system locale and Qt's locale do not have the same numeric separator, for example en_DK or en_ZA --- src/documentvalidator.cpp | 10 ++++++++++ src/mainwindow.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/documentvalidator.cpp b/src/documentvalidator.cpp index a31c18a8..194a55ad 100644 --- a/src/documentvalidator.cpp +++ b/src/documentvalidator.cpp @@ -66,6 +66,16 @@ bool DocumentValidator::validate(const double currentVersion) // WARNING: what should be done in case the locale does not exist on the system? setlocale(LC_NUMERIC, mlt.attribute("LC_NUMERIC").toUtf8().constData()); documentLocale = QLocale(mlt.attribute("LC_NUMERIC")); + + // Make sure Qt locale and C++ locale have the same numeric separator, might not be the case + // With some locales since C++ and Qt use a different database for locales + char *separator = localeconv()->decimal_point; + if (separator != documentLocale.decimalPoint()) { + kDebug()<<"------\n!!! system locale is not similar to Qt's locale... be prepared for bugs!!!\n------"; + // HACK: There is a locale conflict, so set locale to at least have correct decimal point + if (strncmp(separator, ".", 1) == 0) documentLocale = QLocale::c(); + else if (strncmp(separator, ",", 1) == 0) documentLocale = QLocale("fr_FR.UTF-8"); + } } documentLocale.setNumberOptions(QLocale::OmitGroupSeparator); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 53fb77bb..bc41e232 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -113,6 +113,7 @@ #include #include +#include // Uncomment for deeper debugging //#define DEBUG_MAINW @@ -156,6 +157,15 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString & // Init locale QLocale systemLocale = QLocale(); + setlocale(LC_NUMERIC, NULL); + char *separator = localeconv()->decimal_point; + if (separator != systemLocale.decimalPoint()) { + kDebug()<<"------\n!!! system locale is not similar to Qt's locale... be prepared for bugs!!!\n------"; + // HACK: There is a locale conflict, so set locale to at least have correct decimal point + if (strncmp(separator, ".", 1) == 0) systemLocale = QLocale::c(); + else if (strncmp(separator, ",", 1) == 0) systemLocale = QLocale("fr_FR.UTF-8"); + } + systemLocale.setNumberOptions(QLocale::OmitGroupSeparator); QLocale::setDefault(systemLocale); -- 2.39.5