[gimp] app: force re-querying all plug-ins after a language change.



commit 82f9ae1ab75d22fccd411df2a418987fd698cca7
Author: Jehan <jehan girinstud io>
Date:   Wed Apr 27 15:12:16 2022 +0200

    app: force re-querying all plug-ins after a language change.
    
    Some strings might be generated during query() call, in particular all
    strings related to procedure parameters. The core will only know the
    localized version at query() time, so you could end up in situation with
    the core showing you the wrong language. This can be reproduced in the
    Procedure Browser when it shows localized procedure data: when you
    change the language and restart GIMP, if the plug-ins aren't re-queried,
    then it will still show the localization of query time.
    
    Note that it doesn't matter on plug-in side, i.e. anything in the run()
    call is properly localized, included the plug-in GUI using the same
    procedure parameters for widget labels or tooltips. Only the "vision" of
    the core is stuck at what it got when the plug-in was last queried, and
    until the next update of the plug-in.

 app/dialogs/preferences-dialog.c        | 10 ++++++++++
 app/plug-in/gimppluginmanager-restore.c | 23 +++++++++++++++++++++++
 app/plug-in/gimppluginmanager-restore.h |  9 ++++++---
 3 files changed, 39 insertions(+), 3 deletions(-)
---
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index a9a418c18c..1586253af2 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -37,6 +37,7 @@
 #include "core/gimp-utils.h"
 
 #include "plug-in/gimppluginmanager.h"
+#include "plug-in/gimppluginmanager-restore.h"
 
 #include "widgets/gimpaction-history.h"
 #include "widgets/gimpcolorpanel.h"
@@ -388,6 +389,15 @@ prefs_response (GtkWidget *widget,
                 GParamSpec *param_spec = list->data;
 
                 g_string_append_printf (string, "%s\n", param_spec->name);
+
+                if (g_strcmp0 (param_spec->name, "language") == 0)
+                  {
+                    /* A language change will trigger a query() force of
+                     * all plug-ins because some of the localized
+                     * strings might be in the query() step too.
+                     */
+                    gimp_plug_in_manager_force_query_all (gimp->plug_in_manager);
+                  }
               }
 
             prefs_message (GTK_MESSAGE_INFO, FALSE, string->str);
diff --git a/app/plug-in/gimppluginmanager-restore.c b/app/plug-in/gimppluginmanager-restore.c
index 32f12f68d5..76bd50bc33 100644
--- a/app/plug-in/gimppluginmanager-restore.c
+++ b/app/plug-in/gimppluginmanager-restore.c
@@ -194,6 +194,29 @@ gimp_plug_in_manager_restore (GimpPlugInManager  *manager,
   g_object_unref (context);
 }
 
+/*
+ * This function can be used to force to query() all plug-ins at next
+ * GIMP start. It basically empties out the pluginrc file.
+ *
+ * E.g. this is useful when updating the GUI language since some
+ * strings localization may happen in the query() step, such as the
+ * localization of procedure documentation and parameters' titles or
+ * descriptions.
+ */
+void
+gimp_plug_in_manager_force_query_all (GimpPlugInManager *manager)
+{
+  GError *error = NULL;
+  GFile  *pluginrc;
+
+  pluginrc = gimp_plug_in_manager_get_pluginrc (manager);
+  if (! plug_in_rc_write (NULL, pluginrc, &error))
+    {
+      g_printerr ("%s: %s", G_STRFUNC, error->message);
+      g_clear_error (&error);
+    }
+  g_object_unref (pluginrc);
+}
 
 /* search for binaries in the plug-in directory path */
 static void
diff --git a/app/plug-in/gimppluginmanager-restore.h b/app/plug-in/gimppluginmanager-restore.h
index 0389dcf837..3bfe51f7c8 100644
--- a/app/plug-in/gimppluginmanager-restore.h
+++ b/app/plug-in/gimppluginmanager-restore.h
@@ -21,9 +21,12 @@
 #define __GIMP_PLUG_IN_MANAGER_RESTORE_H__
 
 
-void    gimp_plug_in_manager_restore (GimpPlugInManager  *manager,
-                                      GimpContext        *context,
-                                      GimpInitStatusFunc  status_callback);
+void    gimp_plug_in_manager_restore         (GimpPlugInManager  *manager,
+                                              GimpContext        *context,
+                                              GimpInitStatusFunc  status_callback);
+
+void    gimp_plug_in_manager_force_query_all (GimpPlugInManager *manager);
+
 
 
 #endif  /* __GIMP_PLUG_IN_MANAGER_RESTORE_H__ */


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