kdelibs/kdelibs-4.2.1-encoding-qt45...

58 lines
1.6 KiB
Diff

--- kdelibs-4.2.1/kdecore/localization/kcatalog.cpp (Revision 938369)
+++ kdelibs-4.2.1/kdecore/localization/kcatalog.cpp (Revision 938370)
@@ -30,6 +30,24 @@
#include <locale.h>
#include "gettext.h"
+
+static bool s_localeSet = false;
+
+// Initialize the locale very early during application startup
+// This is necessary for e.g. toLocal8Bit() to work, even before
+// a Q[Core]Application exists (David)
+int kInitializeLocale()
+{
+ setlocale(LC_ALL, "");
+#if QT_VERSION >= 0x040500
+ extern Q_CORE_EXPORT bool qt_locale_initialized; // in Qt since 4.5.0
+ qt_locale_initialized = true; // as recommended by Thiago
+#endif
+ s_localeSet = true;
+ return 1;
+}
+Q_CONSTRUCTOR_FUNCTION(kInitializeLocale)
+
// not defined on win32 :(
#ifdef _WIN32
# ifndef LC_MESSAGES
@@ -50,7 +68,6 @@
QByteArray systemLanguage;
- static int localeSet;
static QByteArray currentLanguage;
void setupGettextEnv ();
@@ -62,17 +79,15 @@
return debug << c.d->language << " " << c.d->name << " " << c.d->localeDir;
}
-int KCatalogPrivate::localeSet = 0;
QByteArray KCatalogPrivate::currentLanguage;
KCatalog::KCatalog(const QString & name, const QString & language )
: d( new KCatalogPrivate )
{
- // Set locales only once.
- if (! KCatalogPrivate::localeSet) {
- setlocale(LC_ALL, "");
- KCatalogPrivate::localeSet = 1;
- }
+ // Set locales if the static initializer didn't work
+ if (!s_localeSet) {
+ kInitializeLocale();
+ }
// Find locale directory for this catalog.
QString localeDir = catalogLocaleDir( name, language );