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).
This commit is contained in:
Jehan 2022-07-06 19:33:00 +02:00
parent ca1a0e3650
commit a7a027706b
7 changed files with 73 additions and 11 deletions

View file

@ -67,6 +67,7 @@
#include "app.h" #include "app.h"
#include "errors.h" #include "errors.h"
#include "language.h"
#include "sanity.h" #include "sanity.h"
#include "gimp-debug.h" #include "gimp-debug.h"
@ -193,8 +194,10 @@ app_run (const gchar *full_prog_name,
GFile *default_folder = NULL; GFile *default_folder = NULL;
GFile *gimpdir; GFile *gimpdir;
const gchar *abort_message; const gchar *abort_message;
GError *font_error = NULL; const gchar *current_language;
gint retval = EXIT_SUCCESS; gchar *prev_language = NULL;
GError *font_error = NULL;
gint retval = EXIT_SUCCESS;
if (filenames && filenames[0] && ! filenames[1] && if (filenames && filenames[0] && ! filenames[1] &&
g_file_test (filenames[0], G_FILE_TEST_IS_DIR)) 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); 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 /* Load all data files
*/ */
gimp_restore (gimp, update_status_func, &font_error); 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); gimp_update_auto_check (gimp->edit_config, gimp);
/* Set this after gimp_update_auto_check(). This will be used for the /* Setting properties to be used for the next run. */
* next run.
*/
g_object_set (gimp->edit_config, g_object_set (gimp->edit_config,
/* Set this after gimp_update_auto_check(). */
"config-version", GIMP_VERSION, "config-version", GIMP_VERSION,
/* Set this after gimp_restore(). */
"prev-language", current_language,
NULL); NULL);
loop = run_loop = g_main_loop_new (NULL, FALSE); loop = run_loop = g_main_loop_new (NULL, FALSE);

View file

@ -56,6 +56,7 @@ enum
{ {
PROP_0, PROP_0,
PROP_LANGUAGE, PROP_LANGUAGE,
PROP_PREV_LANGUAGE,
PROP_CONFIG_VERSION, PROP_CONFIG_VERSION,
PROP_INTERPOLATION_TYPE, PROP_INTERPOLATION_TYPE,
PROP_DEFAULT_THRESHOLD, PROP_DEFAULT_THRESHOLD,
@ -183,6 +184,19 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass)
GIMP_PARAM_STATIC_STRINGS | GIMP_PARAM_STATIC_STRINGS |
GIMP_CONFIG_PARAM_RESTART); 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 /* 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 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 * 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); g_free (core_config->language);
core_config->language = g_value_dup_string (value); core_config->language = g_value_dup_string (value);
break; 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: case PROP_INTERPOLATION_TYPE:
core_config->interpolation_type = g_value_get_enum (value); core_config->interpolation_type = g_value_get_enum (value);
break; break;
@ -1203,6 +1221,9 @@ gimp_core_config_get_property (GObject *object,
case PROP_LANGUAGE: case PROP_LANGUAGE:
g_value_set_string (value, core_config->language); g_value_set_string (value, core_config->language);
break; break;
case PROP_PREV_LANGUAGE:
g_value_set_string (value, core_config->prev_language);
break;
case PROP_INTERPOLATION_TYPE: case PROP_INTERPOLATION_TYPE:
g_value_set_enum (value, core_config->interpolation_type); g_value_set_enum (value, core_config->interpolation_type);
break; break;

View file

@ -41,6 +41,7 @@ struct _GimpCoreConfig
GimpGeglConfig parent_instance; GimpGeglConfig parent_instance;
gchar *language; gchar *language;
gchar *prev_language;
GimpInterpolationType interpolation_type; GimpInterpolationType interpolation_type;
gint default_threshold; gint default_threshold;
gchar *plug_in_path; gchar *plug_in_path;

View file

@ -61,6 +61,7 @@ struct _Gimp
gboolean restored; /* becomes TRUE in gimp_restore() */ gboolean restored; /* becomes TRUE in gimp_restore() */
gboolean initialized; /* Fully initialized (only set once at start). */ gboolean initialized; /* Fully initialized (only set once at start). */
gboolean query_all; /* Force query all plug-ins. */
gint busy; gint busy;
guint busy_idle_id; guint busy_idle_id;

View file

@ -21,6 +21,7 @@
#include "config.h" #include "config.h"
#include <langinfo.h>
#include <locale.h> #include <locale.h>
#include <glib.h> #include <glib.h>
@ -33,9 +34,15 @@
#include "language.h" #include "language.h"
void const gchar *
language_init (const gchar *language) language_init (const gchar *language)
{ {
static gchar *actual_language = NULL;
if (actual_language != NULL)
/* Already initialized. */
return actual_language;
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
if (! language && if (! language &&
g_getenv ("LANG") == NULL && g_getenv ("LANG") == NULL &&
@ -731,9 +738,23 @@ language_init (const gchar *language)
/* We already set the locale according to the environment, so just /* We already set the locale according to the environment, so just
* return early if no language is set in gimprc. * return early if no language is set in gimprc.
*/ */
if (! language) if (! language || strlen (language) == 0)
return; {
/* 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, "");
g_setenv ("LANGUAGE", language, TRUE); actual_language = g_strdup (language);
setlocale (LC_ALL, ""); }
return actual_language;
} }

View file

@ -23,7 +23,7 @@
#endif #endif
void language_init (const gchar *language); const gchar * language_init (const gchar *language);
#endif /* __LANGUAGE_H__ */ #endif /* __LANGUAGE_H__ */

View file

@ -474,6 +474,9 @@ gimp_plug_in_manager_query_new (GimpPlugInManager *manager,
{ {
GimpPlugInDef *plug_in_def = list->data; 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) if (plug_in_def->needs_query)
n_plugins++; n_plugins++;
} }