[gimp] app: reload plug-ins when language changes between runs.



commit a7a027706bd0183430ae937f531e4e940e70c68e
Author: Jehan <jehan girinstud io>
Date:   Wed Jul 6 19:33:00 2022 +0200

    app: reload plug-ins when language changes between runs.
    
    Since localization is fully handled plug-in side now (see #8124), we
    need to make sure the query functions are run again for all plug-ins
    when the UI language changes (otherwise we might end up with
    localizations from the previously used languages).
    
    We were already reloading plug-ins when explicitly changing the lang in
    the Preferences, but this new implementation is much better as it's
    generic. In particular, it will also handle the case when the system
    language changes (or when you play with locale environment variables).

 app/app.c                               | 25 ++++++++++++++++++++-----
 app/config/gimpcoreconfig.c             | 21 +++++++++++++++++++++
 app/config/gimpcoreconfig.h             |  1 +
 app/core/gimp.h                         |  1 +
 app/language.c                          | 31 ++++++++++++++++++++++++++-----
 app/language.h                          |  2 +-
 app/plug-in/gimppluginmanager-restore.c |  3 +++
 7 files changed, 73 insertions(+), 11 deletions(-)
---
diff --git a/app/app.c b/app/app.c
index 8e171fe786..5d40b7f7d2 100644
--- a/app/app.c
+++ b/app/app.c
@@ -67,6 +67,7 @@
 
 #include "app.h"
 #include "errors.h"
+#include "language.h"
 #include "sanity.h"
 #include "gimp-debug.h"
 
@@ -193,8 +194,10 @@ app_run (const gchar         *full_prog_name,
   GFile              *default_folder = NULL;
   GFile              *gimpdir;
   const gchar        *abort_message;
-  GError             *font_error = NULL;
-  gint                retval     = EXIT_SUCCESS;
+  const gchar        *current_language;
+  gchar              *prev_language = NULL;
+  GError             *font_error    = NULL;
+  gint                retval        = EXIT_SUCCESS;
 
   if (filenames && filenames[0] && ! filenames[1] &&
       g_file_test (filenames[0], G_FILE_TEST_IS_DIR))
@@ -309,6 +312,17 @@ app_run (const gchar         *full_prog_name,
    */
   gimp_initialize (gimp, update_status_func);
 
+  g_object_get (gimp->edit_config,
+                "prev-language", &prev_language,
+                NULL);
+  /* Language was already initialized. I call this again only to get the
+   * actual language information.
+   */
+  current_language = language_init (NULL);
+  gimp->query_all = (prev_language == NULL ||
+                     g_strcmp0 (prev_language, current_language) != 0);
+  g_free (prev_language);
+
   /*  Load all data files
    */
   gimp_restore (gimp, update_status_func, &font_error);
@@ -323,11 +337,12 @@ app_run (const gchar         *full_prog_name,
    */
   gimp_update_auto_check (gimp->edit_config, gimp);
 
-  /* Set this after gimp_update_auto_check(). This will be used for the
-   * next run.
-   */
+  /* Setting properties to be used for the next run.  */
   g_object_set (gimp->edit_config,
+                /* Set this after gimp_update_auto_check(). */
                 "config-version", GIMP_VERSION,
+                /* Set this after gimp_restore(). */
+                "prev-language",  current_language,
                 NULL);
 
   loop = run_loop = g_main_loop_new (NULL, FALSE);
diff --git a/app/config/gimpcoreconfig.c b/app/config/gimpcoreconfig.c
index b9230a841e..e41a8705f6 100644
--- a/app/config/gimpcoreconfig.c
+++ b/app/config/gimpcoreconfig.c
@@ -56,6 +56,7 @@ enum
 {
   PROP_0,
   PROP_LANGUAGE,
+  PROP_PREV_LANGUAGE,
   PROP_CONFIG_VERSION,
   PROP_INTERPOLATION_TYPE,
   PROP_DEFAULT_THRESHOLD,
@@ -183,6 +184,19 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
                            GIMP_PARAM_STATIC_STRINGS |
                            GIMP_CONFIG_PARAM_RESTART);
 
+  /* The language which was being used previously. If the "language"
+   * property was at default (i.e. System language), this
+   * must map to the actually used language for UI display, because if
+   * this changed (for whatever reasons, e.g. changed environment
+   * variables, or actually changing system language), we want to reload
+   * plug-ins.
+   */
+  GIMP_CONFIG_PROP_STRING (object_class, PROP_PREV_LANGUAGE,
+                           "prev-language",
+                           "Language used in previous run",
+                           NULL, NULL,
+                           GIMP_PARAM_STATIC_STRINGS);
+
   /* This is the version of the config files, which must map to the
    * version of GIMP. It is used right now only to detect the last run
    * version in order to detect an update. It could be used later also
@@ -902,6 +916,10 @@ gimp_core_config_set_property (GObject      *object,
       g_free (core_config->language);
       core_config->language = g_value_dup_string (value);
       break;
+    case PROP_PREV_LANGUAGE:
+      g_free (core_config->prev_language);
+      core_config->prev_language = g_value_dup_string (value);
+      break;
     case PROP_INTERPOLATION_TYPE:
       core_config->interpolation_type = g_value_get_enum (value);
       break;
@@ -1203,6 +1221,9 @@ gimp_core_config_get_property (GObject    *object,
     case PROP_LANGUAGE:
       g_value_set_string (value, core_config->language);
       break;
+    case PROP_PREV_LANGUAGE:
+      g_value_set_string (value, core_config->prev_language);
+      break;
     case PROP_INTERPOLATION_TYPE:
       g_value_set_enum (value, core_config->interpolation_type);
       break;
diff --git a/app/config/gimpcoreconfig.h b/app/config/gimpcoreconfig.h
index 72bdcd4206..3ebc62bea9 100644
--- a/app/config/gimpcoreconfig.h
+++ b/app/config/gimpcoreconfig.h
@@ -41,6 +41,7 @@ struct _GimpCoreConfig
   GimpGeglConfig          parent_instance;
 
   gchar                  *language;
+  gchar                  *prev_language;
   GimpInterpolationType   interpolation_type;
   gint                    default_threshold;
   gchar                  *plug_in_path;
diff --git a/app/core/gimp.h b/app/core/gimp.h
index a543520d32..0e9d91a2de 100644
--- a/app/core/gimp.h
+++ b/app/core/gimp.h
@@ -61,6 +61,7 @@ struct _Gimp
 
   gboolean                restored;    /* becomes TRUE in gimp_restore() */
   gboolean                initialized; /* Fully initialized (only set once at start). */
+  gboolean                query_all;   /* Force query all plug-ins. */
 
   gint                    busy;
   guint                   busy_idle_id;
diff --git a/app/language.c b/app/language.c
index 581ff67802..f50bba737a 100644
--- a/app/language.c
+++ b/app/language.c
@@ -21,6 +21,7 @@
 
 #include "config.h"
 
+#include <langinfo.h>
 #include <locale.h>
 
 #include <glib.h>
@@ -33,9 +34,15 @@
 #include "language.h"
 
 
-void
+const gchar *
 language_init (const gchar *language)
 {
+  static gchar *actual_language = NULL;
+
+  if (actual_language != NULL)
+    /* Already initialized. */
+    return actual_language;
+
 #ifdef G_OS_WIN32
   if (! language                       &&
       g_getenv ("LANG")        == NULL &&
@@ -731,9 +738,23 @@ language_init (const gchar *language)
   /*  We already set the locale according to the environment, so just
    *  return early if no language is set in gimprc.
    */
-  if (! language)
-    return;
+  if (! language || strlen (language) == 0)
+    {
+      /* Using system language. It doesn't matter too much that the string
+       * format is different when using system or preference-set language,
+       * because this string is only used for comparison. As long as 2
+       * similar run have the same settings, the strings will be
+       * identical.
+       */
+      actual_language = g_strdup (nl_langinfo (_NL_IDENTIFICATION_LANGUAGE));
+    }
+  else
+    {
+      g_setenv ("LANGUAGE", language, TRUE);
+      setlocale (LC_ALL, "");
+
+      actual_language = g_strdup (language);
+    }
 
-  g_setenv ("LANGUAGE", language, TRUE);
-  setlocale (LC_ALL, "");
+  return actual_language;
 }
diff --git a/app/language.h b/app/language.h
index 39d692924e..7e542d6cb9 100644
--- a/app/language.h
+++ b/app/language.h
@@ -23,7 +23,7 @@
 #endif
 
 
-void language_init (const gchar *language);
+const gchar * language_init (const gchar *language);
 
 
 #endif /* __LANGUAGE_H__ */
diff --git a/app/plug-in/gimppluginmanager-restore.c b/app/plug-in/gimppluginmanager-restore.c
index 6ac77f1c8e..05cd12c683 100644
--- a/app/plug-in/gimppluginmanager-restore.c
+++ b/app/plug-in/gimppluginmanager-restore.c
@@ -474,6 +474,9 @@ gimp_plug_in_manager_query_new (GimpPlugInManager  *manager,
     {
       GimpPlugInDef *plug_in_def = list->data;
 
+      if (manager->gimp->query_all)
+        gimp_plug_in_def_set_needs_query (plug_in_def, TRUE);
+
       if (plug_in_def->needs_query)
         n_plugins++;
     }


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