Fix kleopatra language detection
authorAndre Heinecke <aheinecke@intevation.de>
Fri, 4 Mar 2016 10:47:00 +0000 (11:47 +0100)
committerAndre Heinecke <aheinecke@intevation.de>
Fri, 4 Mar 2016 10:47:00 +0000 (11:47 +0100)
* Makefile.am (EXTRA_DIST): Add patch.
* patches/ki18n/0001-Use-QLocale-system-uiLanguages-as-fallback.patch:
 New.
* src/inst-kleopatra.nsi, src/uninst-kleopatra.nsi: Remove
 klanguageoverrides handling.

--
The language overrides did not work as they were not read from the
global folder. This new patch is better. (KDE review 127275)

Makefile.am
patches/ki18n/0001-Use-QLocale-system-uiLanguages-as-fallback.patch [new file with mode: 0755]
src/inst-kleopatra.nsi
src/uninst-kleopatra.nsi

index 81dbec3..e167793 100644 (file)
@@ -37,6 +37,7 @@ EXTRA_DIST = autogen.sh README.GIT ONEWS \
         patches/w32pth-2.0.5/workaround-broken-libtool.patch \
         patches/qttools/disable-most-tools.patch \
         patches/ki18n/no-tests.patch \
+        patches/ki18n/0001-Use-QLocale-system-uiLanguages-as-fallback.patch \
         patches/gpgme-1.6.0/0001-w32-Fallback-to-2.1-reg-key-for-gpgconf-search.patch \
         patches/gpgmepp/0002-disable-variants.patch \
         patches/kmime/0001-Check-for-and-replace-strcasestr.patch \
diff --git a/patches/ki18n/0001-Use-QLocale-system-uiLanguages-as-fallback.patch b/patches/ki18n/0001-Use-QLocale-system-uiLanguages-as-fallback.patch
new file mode 100755 (executable)
index 0000000..7984193
--- /dev/null
@@ -0,0 +1,100 @@
+#! /bin/sh
+patch -p1 -l -f $* < $0
+exit $?
+
+From 7a2c71e618d97f5d4a3bdf1ba10fc36c638f17ba Mon Sep 17 00:00:00 2001
+From: Andre Heinecke <aheinecke@intevation.de>
+Date: Fri, 4 Mar 2016 11:26:06 +0100
+Subject: [PATCH] Use QLocale::system uiLanguages as fallback
+
+This fixes locale initialisation on platforms that don't use
+environment variables for language settings. (Windows)
+---
+ src/klocalizedstring.cpp | 54 ++++++++++++++++++++++++++++++------------------
+ 1 file changed, 34 insertions(+), 20 deletions(-)
+
+diff --git a/src/klocalizedstring.cpp b/src/klocalizedstring.cpp
+index b24fe9b..e1f71dd 100644
+--- a/src/klocalizedstring.cpp
++++ b/src/klocalizedstring.cpp
+@@ -95,6 +95,30 @@ static void splitLocale(const QString &aLocale,
+     language = locale;
+ }
+
++static void appendLocaleString(QStringList &languages, const QString &value)
++{
++    // Process the value to create possible combinations.
++    QString language, country, modifier, charset;
++    splitLocale(value, language, country, modifier, charset);
++
++    if (!country.isEmpty() && !modifier.isEmpty()) {
++        languages +=   language + QLatin1Char('_')
++                       + country + QLatin1Char('@')
++                       + modifier;
++    }
++    // NOTE: Priority is unclear in case both the country and
++    // the modifier are present. Should really language@modifier be of
++    // higher priority than language_country?
++    // In at least one case (Serbian language), it is better this way.
++    if (!modifier.isEmpty()) {
++        languages += language + QLatin1Char('@') + modifier;
++    }
++    if (!country.isEmpty()) {
++        languages += language + QLatin1Char('_') + country;
++    }
++    languages += language;
++}
++
+ static void appendLanguagesFromVariable(QStringList &languages,
+                                         const char *envar, bool isList = false)
+ {
+@@ -104,30 +128,19 @@ static void appendLanguagesFromVariable(QStringList &languages,
+         if (isList) {
+             languages += value.split(QLatin1Char(':'));
+         } else {
+-            // Process the value to create possible combinations.
+-            QString language, country, modifier, charset;
+-            splitLocale(value, language, country, modifier, charset);
+-
+-            if (!country.isEmpty() && !modifier.isEmpty()) {
+-                languages +=   language + QLatin1Char('_')
+-                               + country + QLatin1Char('@')
+-                               + modifier;
+-            }
+-            // NOTE: Priority is unclear in case both the country and
+-            // the modifier are present. Should really language@modifier be of
+-            // higher priority than language_country?
+-            // In at least one case (Serbian language), it is better this way.
+-            if (!modifier.isEmpty()) {
+-                languages += language + QLatin1Char('@') + modifier;
+-            }
+-            if (!country.isEmpty()) {
+-                languages += language + QLatin1Char('_') + country;
+-            }
+-            languages += language;
++            appendLocaleString(languages, value);
+         }
+     }
+ }
+
++static void appendLanguagesFromQLocale(QStringList &languages, const QLocale &locale)
++{
++    const QStringList uiLangs = locale.uiLanguages();
++    Q_FOREACH (QString value, uiLangs) {
++        appendLocaleString(languages, value.replace(QLatin1Char('-'), QLatin1Char('_')));
++    }
++}
++
+ // Extract the first country code from a list of language_COUNTRY strings.
+ // Country code is converted to all lower case letters.
+ static QString extractCountry(const QStringList &languages)
+@@ -333,6 +346,7 @@ void KLocalizedStringPrivateStatics::initializeLocaleLanguages()
+     appendLanguagesFromVariable(localeLanguages, "LC_ALL");
+     appendLanguagesFromVariable(localeLanguages, "LC_MESSAGES");
+     appendLanguagesFromVariable(localeLanguages, "LANG");
++    appendLanguagesFromQLocale(localeLanguages, QLocale::system());
+ }
+
+ KLocalizedString::KLocalizedString()
+--
+2.1.4
index 0c48dc0..b84b029 100644 (file)
@@ -214,59 +214,6 @@ ${MementoSection} "Kleopatra" SEC_kleopatra
   FileClose $1
   pop $1
 
-  push $1
-  FileOpen $1 "$INSTDIR\share\klanguageoverridesrc" "w"
-  FileWrite $1 '[Language] $\r$\n'
-  StrCmp $LANGUAGE "1031" german_locale 0
-  StrCmp $LANGUAGE "1025" arabic 0
-  StrCmp $LANGUAGE "1029" czech 0
-  StrCmp $LANGUAGE "1049" russian 0
-  StrCmp $LANGUAGE "1036" french 0
-  StrCmp $LANGUAGE "1034" spanish 0
-  StrCmp $LANGUAGE "1040" italian 0
-  StrCmp $LANGUAGE "1046" portugese 0
-  StrCmp $LANGUAGE "2070" portugese_br 0
-  StrCmp $LANGUAGE "2052" simpchinese 0
-  StrCmp $LANGUAGE "1028" tradchinese 0
-  FileWrite $1 'kleopatra=@ByteArray(en) $\r$\n'
-  Goto lang_done
-german_locale:
-  FileWrite $1 'kleopatra=@ByteArray(de) $\r$\n'
-  Goto lang_done
-arabic:
-  FileWrite $1 'kleopatra=@ByteArray(ar) $\r$\n'
-  Goto lang_done
-czech:
-  FileWrite $1 'kleopatra=@ByteArray(cs) $\r$\n'
-  Goto lang_done
-russian:
-  FileWrite $1 'kleopatra=@ByteArray(ru) $\r$\n'
-  Goto lang_done
-french:
-  FileWrite $1 'kleopatra=@ByteArray(fr) $\r$\n'
-  Goto lang_done
-spanish:
-  FileWrite $1 'kleopatra=@ByteArray(es) $\r$\n'
-  Goto lang_done
-italian:
-  FileWrite $1 'kleopatra=@ByteArray(it) $\r$\n'
-  Goto lang_done
-portugese:
-  FileWrite $1 'kleopatra=@ByteArray(pt) $\r$\n'
-  Goto lang_done
-portugese_br:
-  FileWrite $1 'kleopatra=@ByteArray(pt_BR) $\r$\n'
-  Goto lang_done
-simpchinese:
-  FileWrite $1 'kleopatra=@ByteArray(zh_CN) $\r$\n'
-  Goto lang_done
-tradchinese:
-  FileWrite $1 'kleopatra=@ByteArray(zh_TW) $\r$\n'
-  Goto lang_done
-lang_done:
-  FileClose $1
-  pop $1
-
   SetOutPath "$INSTDIR\share\QtProject"
   # We want kleopatra logging for debugging
   push $1
index 7c3a04d..374c348 100644 (file)
@@ -175,7 +175,6 @@ Section "-un.kleopatra"
   RmDir "$INSTDIR\share\kservices5\"
 
   Delete "$INSTDIR\share\kdeglobals"
-  Delete "$INSTDIR\share\klanguageoverridesrc"
   Delete "$INSTDIR\share\QtProject\qtlogging.ini"
 #  Delete "$INSTDIR\share\apps\kwatchgnupg\pics\kwatchgnupg2.png"
 #  Delete "$INSTDIR\share\apps\kwatchgnupg\pics\kwatchgnupg.png"