From a56de78b0115960dcc09e12a4b5a7eb9cf6630d8 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Wed, 30 Dec 2009 00:38:31 +0100 Subject: [PATCH] app: add "language" gimprc option and set the language accordingly --- app/app.c | 28 +++++++++++++++++++++++++--- app/config/gimpcoreconfig.c | 14 ++++++++++++++ app/config/gimpcoreconfig.h | 1 + app/config/gimprc-blurbs.h | 3 +++ app/main.c | 6 ++++++ 5 files changed, 49 insertions(+), 3 deletions(-) diff --git a/app/app.c b/app/app.c index ce4cb8fbf6..0c9bd87a72 100644 --- a/app/app.c +++ b/app/app.c @@ -20,6 +20,7 @@ #include #include #include +#include #ifdef HAVE_SYS_PARAM_H #include @@ -64,9 +65,11 @@ /* local prototypes */ -static void app_init_update_none (const gchar *text1, +static void app_init_update_noop (const gchar *text1, const gchar *text2, gdouble percentage); +static void app_init_language (const gchar *language); + static gboolean app_exit_after_callback (Gimp *gimp, gboolean kill_it, GMainLoop *loop); @@ -183,6 +186,9 @@ app_run (const gchar *full_prog_name, config = GIMP_BASE_CONFIG (gimp->config); + /* change the locale if a language if specified */ + app_init_language (gimp->config->language); + /* initialize lowlevel stuff */ swap_is_ok = base_init (config, be_verbose, use_cpu_accel); @@ -194,7 +200,7 @@ app_run (const gchar *full_prog_name, #endif if (! update_status_func) - update_status_func = app_init_update_none; + update_status_func = app_init_update_noop; /* Create all members of the global Gimp instance which need an already * parsed gimprc, e.g. the data factories @@ -258,10 +264,26 @@ app_run (const gchar *full_prog_name, /* private functions */ static void -app_init_update_none (const gchar *text1, +app_init_update_noop (const gchar *text1, const gchar *text2, gdouble percentage) { + /* deliberately do nothing */ +} + +static void +app_init_language (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; + + g_printerr ("Setting language to %s\n", language); + + g_setenv ("LANGUAGE", language, TRUE); + setlocale (LC_ALL, ""); } static gboolean diff --git a/app/config/gimpcoreconfig.c b/app/config/gimpcoreconfig.c index 694f56cd37..392326f6fe 100644 --- a/app/config/gimpcoreconfig.c +++ b/app/config/gimpcoreconfig.c @@ -49,6 +49,7 @@ enum { PROP_0, + PROP_LANGUAGE, PROP_INTERPOLATION_TYPE, PROP_PLUG_IN_PATH, PROP_MODULE_PATH, @@ -133,6 +134,11 @@ gimp_core_config_class_init (GimpCoreConfigClass *klass) object_class->set_property = gimp_core_config_set_property; object_class->get_property = gimp_core_config_get_property; + GIMP_CONFIG_INSTALL_PROP_STRING (object_class, PROP_LANGUAGE, + "language", LANGUAGE_BLURB, + NULL, /* take from environment */ + GIMP_PARAM_STATIC_STRINGS | + GIMP_CONFIG_PARAM_RESTART); GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_INTERPOLATION_TYPE, "interpolation-type", INTERPOLATION_TYPE_BLURB, @@ -422,6 +428,7 @@ gimp_core_config_finalize (GObject *object) { GimpCoreConfig *core_config = GIMP_CORE_CONFIG (object); + g_free (core_config->language); g_free (core_config->plug_in_path); g_free (core_config->module_path); g_free (core_config->interpreter_path); @@ -468,6 +475,10 @@ gimp_core_config_set_property (GObject *object, switch (property_id) { + case PROP_LANGUAGE: + g_free (core_config->language); + core_config->language = g_value_dup_string (value); + break; case PROP_INTERPOLATION_TYPE: core_config->interpolation_type = g_value_get_enum (value); break; @@ -652,6 +663,9 @@ gimp_core_config_get_property (GObject *object, switch (property_id) { + case PROP_LANGUAGE: + g_value_set_string (value, core_config->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 1e5e760a0a..0ff23f21e5 100644 --- a/app/config/gimpcoreconfig.h +++ b/app/config/gimpcoreconfig.h @@ -39,6 +39,7 @@ struct _GimpCoreConfig { GimpBaseConfig parent_instance; + gchar *language; GimpInterpolationType interpolation_type; gchar *plug_in_path; gchar *module_path; diff --git a/app/config/gimprc-blurbs.h b/app/config/gimprc-blurbs.h index 890adb8dd0..58cddcf4b7 100644 --- a/app/config/gimprc-blurbs.h +++ b/app/config/gimprc-blurbs.h @@ -198,6 +198,9 @@ N_("Sets the level of interpolation used for scaling and other " \ #define INTERPRETER_PATH_BLURB \ "Sets the interpreter search path." +#define LANGUAGE_BLURB \ +N_("Specifies the language to use.") + #define LAST_OPENED_SIZE_BLURB \ N_("How many recently opened image filenames to keep on the File menu.") diff --git a/app/main.c b/app/main.c index da86aeaa07..3ca6c8e638 100644 --- a/app/main.c +++ b/app/main.c @@ -615,6 +615,12 @@ gimp_init_malloc (void) static void gimp_init_i18n (void) { + /* We may change the locale later if the user specifies a language + * in the gimprc file. Here we are just initializing the locale + * according to the environment variables and set up the paths to + * the message catalogs. + */ + setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE"-libgimp", gimp_locale_directory ());