Hi Andreas,
The relevant part of the patch is attached.
(The other parts were to make sure system-gettext is used, not the
code included in enigma).

I exploit that setlocale returns NULL when the locale is not available:
if (setlocale (LC_MESSAGES, val) != NULL)
then I just retry with locale + ".UTF-8"

Regards,
Erich

On Mon, Jan 27, 2014 at 1:13 AM, Andreas Lochmann
<and.lochm...@googlemail.com> wrote:
>
> Hi Erich,
>
> thank you for investigating into this problem,
> I always wondered myself what might be the
> bug here.
>
> Could you send me your brute-force fix to
> take a look at?
>
> Best regards,
> Andreas
>
>
> Am 23.01.2014 21:02, schrieb Erich Schubert:
>> Hi all,
>> I've uploaded a new enigma build with some tiny fixes to Debian (which
>> will also end up in Ubuntu).
>>
>> There was one issue that got really on my nerves: locales.
>>
>> First of all, there is a tiny bug: there is no en_EN, only en_GB and en_US. 
>> ;-)
>>
>> So locales weren't working for lots of people on Linux.
>> I've looked into this, and unfortunately, locale names are quite fragile.
>> Current enigma assumes that all supported locales are installed, and
>> have well-known names. And unfortunately, gettext doesn't try too hard
>> to solve any ambiguities.
>>
>> On my system, the installed locales are (I try to save disk space):
>> ---
>> C
>> C.UTF-8
>> de_DE.utf8
>> POSIX
>> ---
>> Enigma on the other hand tries to use "de_DE", which is an alias for
>> "de_DE.ISO-8859-1" - and which is not available on my system.
>>
>> The hotfix I uploaded is more of a brute force approach. When a locale
>> is not available (setlocale returning null), it will try appending
>> .UTF8 - because the only cases I'm aware of where the default charset
>> changed - and retry.
>> For locales not available, the flag icon will be there but not work.
>>
>> Maybe we can A) investigate, if the two-letter codes maybe work
>> better? B) setting $LANGUAGE instead of $LANG is more robust, C)
>> options to enumerate available locales, akin to "locale -a", D) grab
>> the system locale, see if it matches a known language, and use it then
>> and E) not show flag icons that seem to be unsupported (setlocale
>> returning null).
>>
>> Since I'm not sure if the "localename" is used somewhere except in the
>> language chooser GUI and gettext, I didn't want to do more invasive
>> changes.
>>
>> As for A), this doesn't appear to be the case:
>> "" -> de_DE.utf8
>> de -> (null)
>> en -> (null)
>> de_DE -> (null)
>> de_DE.UTF-8 -> de_DE.UTF-8
>>
>> As you can see, the .UTF-8 postfix is needed on my system. The return
>> of "" can be used as a default, and can be recognized as "de" locale.
>> If I additionally generate the "de_DE.ISO-8859-1" locale, then "de_DE"
>> works, but likely yields the latin1 encoded locale (which doesn't have
>> the € symbol)
>>
>> An alternate approach would be to have a list of locale names for each
>> language, for example for German we could try
>> de_DE.UTF-8, de_DE.ISO-8859-15@euro, de_DE.ISO-8859-1, de_DE, de,
>> de_AT.UTF-8, de_CH.UTF-8
>> and choose whichever is accepted by "setlocale" first. If none is
>> accepted, drop it at runtime from the locales list (E).
>>
>> best regards,
>> Erich Schubert
>>
>> _______________________________________________
>> Enigma-devel mailing list
>> Enigma-devel@nongnu.org
>> https://lists.nongnu.org/mailman/listinfo/enigma-devel
>
>



-- 

best regards,
Erich Schubert
Index: enigma-1.20/src/nls.cc
===================================================================
--- enigma-1.20.orig/src/nls.cc	2014-01-23 18:58:10.000000000 +0100
+++ enigma-1.20/src/nls.cc	2014-01-23 19:01:44.000000000 +0100
@@ -2,6 +2,7 @@
 #include "main.hh"
 #include "ecl_system.hh"
 
+#include <locale.h>
 #include <iostream>
 #include <string>
 #include <cstdlib>
@@ -14,26 +15,38 @@
 static char lang_env[256];
 #endif
 
-static void my_setenv (const std::string &var, const std::string &val)
+static char localeutf[256];
+
+static void my_setenv (const char* var, const char* val)
 {
 #if defined (HAVE_SETENV)
-    setenv(var.c_str(), val.c_str(), 1);
+    setenv(var, val, 1);
 #elif defined (HAVE_PUTENV)
-    snprintf (lang_env, sizeof(lang_env), "%s=%s", var.c_str(), val.c_str());
+    snprintf (lang_env, sizeof(lang_env), "%s=%s", var, val);
     putenv(lang_env);
 #endif
 }
 
 void nls::SetMessageLocale (const std::string &language)
 {
-    if (language != "")
-        my_setenv ("LANG", language);
+    if (language != "") {
+        if (setlocale (LC_MESSAGES, language.c_str()) != NULL) {
+            my_setenv ("LANG", language.c_str());
+        } else {
+            // Second attempt: lang + .UTF-8
+            snprintf(localeutf, sizeof(localeutf), "%s.UTF-8", language.c_str());
+            if (setlocale (LC_MESSAGES, localeutf) != NULL) {
+                my_setenv ("LANG", localeutf);
+            }
+        }
+    }
 
 #if defined(ENABLE_NLS) && defined(HAVE_LC_MESSAGES)
     // Hack to fool libintl into changing the message locale more than
     // once
     setlocale (LC_MESSAGES, "C");
     setlocale (LC_MESSAGES, ""); //language.c_str());
+
 #endif
 
     std::string li = ecl::SysMessageLocaleName();
Index: enigma-1.20/src/nls.hh
===================================================================
--- enigma-1.20.orig/src/nls.hh	2014-01-23 18:43:25.000000000 +0100
+++ enigma-1.20/src/nls.hh	2014-01-23 19:00:51.000000000 +0100
@@ -27,7 +27,7 @@
     const Language languages[] = {
         { "default",    "",      "par" },
         { "Deutsch",    "de_DE", "flags25x15/de" },
-        { "English",    "en_EN", "flags25x15/gb" },
+        { "English",    "en_GB", "flags25x15/gb" },
         { "Español",    "es_ES", "flags25x15/es" },
         { "Français",   "fr_FR", "flags25x15/fr" },
         { "Italiano",   "it_IT", "flags25x15/it" },
_______________________________________________
Enigma-devel mailing list
Enigma-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/enigma-devel

Reply via email to