[gimp] plug-ins: better parse locales.



commit 65e8521402e5cb2e29f55503fb5fd7e2df6917d5
Author: Jehan <jehan girinstud io>
Date:   Wed Feb 1 01:03:32 2017 +0100

    plug-ins: better parse locales.
    
    Be a little cleverer about what locale we care about in the context of
    the help system. Variants and encoding in particular are of no interest
    to us.
    Let's also always add a base language (like "en" for "en_GB") rather
    than fully trusting g_get_language_names() since it seems to return
    funny results on some platform.
    Finally check for duplicates before adding to language list.

 plug-ins/help/gimphelp.c |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
---
diff --git a/plug-ins/help/gimphelp.c b/plug-ins/help/gimphelp.c
index a73a9ba..e46dfb5 100644
--- a/plug-ins/help/gimphelp.c
+++ b/plug-ins/help/gimphelp.c
@@ -127,6 +127,16 @@ gimp_help_parse_locales (const gchar *help_locales)
       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
@@ -141,8 +151,36 @@ gimp_help_parse_locales (const gchar *help_locales)
       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]