[gimp] app, plug-ins: move the locale processing code in the core.



commit 08e8c0e4f87801decc57029fa611887d2f18628e
Author: Jehan <jehan girinstud io>
Date:   Wed Feb 1 03:10:13 2017 +0100

    app, plug-ins: move the locale processing code in the core.
    
    The colon-separated list used in the plugin originally comes from
    gimp_help_get_locales() anyway. My previous code was using different
    lists of locales in different places, which was inconsistent.

 app/widgets/gimphelp.c   |   85 ++++++++++++++++++++++++++++++++++++++++++++-
 plug-ins/help/gimphelp.c |   57 +------------------------------
 2 files changed, 84 insertions(+), 58 deletions(-)
---
diff --git a/app/widgets/gimphelp.c b/app/widgets/gimphelp.c
index 82afa85..cc3550d 100644
--- a/app/widgets/gimphelp.c
+++ b/app/widgets/gimphelp.c
@@ -591,12 +591,93 @@ gimp_help_get_default_domain_uri (Gimp *gimp)
 static gchar *
 gimp_help_get_locales (Gimp *gimp)
 {
-  GimpGuiConfig *config = GIMP_GUI_CONFIG (gimp->config);
+  GimpGuiConfig  *config = GIMP_GUI_CONFIG (gimp->config);
+  gchar         **names;
+  gchar          *locales      = NULL;
+  GList          *locales_list = NULL;
+  GList          *iter;
+  gint            i;
 
   if (config->help_locales && strlen (config->help_locales))
     return g_strdup (config->help_locales);
 
-  return g_strjoinv (":", (gchar **) g_get_language_names ());
+  /* Process locales. */
+  names = (gchar **) g_get_language_names ();
+  for (i = 0; names[i]; i++)
+    {
+      gchar *locale = g_strdup (names[i]);
+      gchar *c;
+
+      /* We don't care about encoding in context of our help system. */
+      c = strchr (locale, '.');
+      if (c)
+        *c = '\0';
+      /* We don't care about variants as well. */
+      c = strchr (locale, '@');
+      if (c)
+        *c = '\0';
+      /* Apparently some systems (i.e. Windows) would return a value as
+       * IETF language tag, which is a different format from POSIX
+       * locale; especially it would separate the lang and the region
+       * with an hyphen instead of an underscore.
+       * Actually the difference is much deeper, and IETF language tags
+       * can have extended language subtags, a script subtag, variants,
+       * moreover using different codes.
+       * We'd actually need to look into this in details (TODO).
+       * this dirty hack should do for easy translation at least (like
+       * "en-GB" -> "en_GB).
+       * Cf. bug 777754.
+       */
+      c = strchr (locale, '-');
+      if (c)
+        *c = '_';
+      if (locale && *locale &&
+          ! g_list_find_custom (locales_list, locale,
+                                (GCompareFunc) g_strcmp0))
+        {
+          gchar *base;
+
+          /* Adding this locale. */
+          locales_list = g_list_prepend (locales_list, locale);
+
+          /* Adding the base language as well. */
+          base = strdup (locale);
+          c = strchr (base, '_');
+          if (c)
+            *c = '\0';
+          if (base && *base &&
+              ! g_list_find_custom (locales_list, base,
+                                    (GCompareFunc) g_strcmp0))
+            {
+              locales_list = g_list_prepend (locales_list, base);
+            }
+          else
+            {
+              g_free (base);
+            }
+        }
+      else
+        {
+          /* Avoid duplicates. */
+          g_free (locale);
+        }
+    }
+  locales_list = g_list_reverse (locales_list);
+
+  /* Finally generate the colon-separated value. */
+  if (locales_list)
+    {
+      locales = g_strdup (locales_list->data);
+      for (iter = locales_list->next; iter; iter = iter->next)
+        {
+          gchar *temp = locales;
+          locales = g_strconcat (temp, ":", iter->data, NULL);
+          g_free (temp);
+        }
+    }
+  g_list_free_full (locales_list, g_free);
+
+  return locales;
 }
 
 static GFile *
diff --git a/plug-ins/help/gimphelp.c b/plug-ins/help/gimphelp.c
index e46dfb5..cbb9280 100644
--- a/plug-ins/help/gimphelp.c
+++ b/plug-ins/help/gimphelp.c
@@ -125,62 +125,7 @@ gimp_help_parse_locales (const gchar *help_locales)
   for (p = strchr (s, ':'); p; p = strchr (s, ':'))
     {
       gchar *new = g_strndup (s, p - s);
-      gchar *c;
-
-      /* After a dot is displayed the optional encoding.
-       * We don't care in context of our help system.
-       */
-      c = strchr (new, '.');
-      if (c)
-        *c = '\0';
-      /* We don't care about variants as well. */
-      c = strchr (new, '@');
-      if (c)
-        *c = '\0';
-      /* Apparently some systems (i.e. Windows) would return a value as
-       * IETF language tag, which is a different format from POSIX
-       * locale; especially it would separate the lang and the region
-       * with an hyphen instead of an underscore.
-       * Actually the difference is much deeper, and IETF language tags
-       * can have extended language subtags, a script subtag, variants,
-       * moreover using different codes.
-       * We'd actually need to look into this in details (TODO).
-       * this dirty hack should do for easy translation at least (like
-       * "en-GB" -> "en_GB).
-       */
-      c = strchr (new, '-');
-      if (c)
-        *c = '_';
-      if (new && *new &&
-          ! g_list_find_custom (locales, new,
-                                (GCompareFunc) g_strcmp0))
-        {
-          gchar *base;
-
-          /* Adding this locale. */
-          locales = g_list_append (locales, new);
-
-          /* Adding the base language as well. */
-          base = strdup (new);
-          c = strchr (base, '_');
-          if (c)
-            *c = '\0';
-          if (base && *base &&
-              ! g_list_find_custom (locales, base,
-                                    (GCompareFunc) g_strcmp0))
-            {
-              locales = g_list_append (locales, base);
-            }
-          else
-            {
-              g_free (base);
-            }
-        }
-      else
-        {
-          g_free (new);
-        }
-
+      locales = g_list_append (locales, new);
       s = p + 1;
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]