From 81b569cb8ca69df21b7db3c63857a5e4e14aac92 Mon Sep 17 00:00:00 2001 From: Jehan Date: Mon, 4 Jul 2022 16:37:08 +0200 Subject: [PATCH] Issue #8124: plug-in localization now totally moved plug-in side. Plug-in localization was always partially plug-in side, especially for things like custom GUI. But labels or blurb in GIMP (such as in menus or action search) were localizing GIMP side. It had many drawbacks: - To get menu localization, a plug-in had to set up gettext, even though they might want to use something else for their GUI (after all, giving facilities for gettext is a good idea, but there is no reason to force using this system). - There was a complex internal system passing the localization domain name, as well as the catalog file system path to core, then through various classes which we can now get rid of. - There could be domain name clashes, if 2 plug-ins were to use the same i18n domain name. This was handled in now removed functions gimp_plug_in_manager_get_locale_domains() by simply keeping a unique one (and gimp_plug_in_manager_bind_text_domains() would just bind the domain to the kept directory). In other words, one of the duplicate plug-ins would use the wrong catalog. We could try to make the whole thing more complicated or try to forbid plug-ins to use any random name (in particular made easier with the new extension wrapper). But anyway this whole issue doesn't happen anymore if localization is fully made plug-in side, so why bother? I tried to evaluate the advantages of the core-side localization of plug-in labels/blurbs and could only find one theoretical: if we wanted to keep access to the original English text. This could be useful (theoretically) if we wanted to search (e.g. in the action search) in both localized and English text; or if we wanted to be able to swap easily en/l10n text in a UI without reload. But even if we were to ever do this, it would only be possible for plug-ins (GEGL operations in particular are localized GEGL-side), so it lacks consistency. And it's unsure why special-casing English should really make sense for other language natives who want text in their lang, and search in their lang. They don't necessarily care about original. So in the end, I decided to simplify the whole thing, make localization of plug-ins a plug-in side thing. Core will only receive translated text and that's it. It cuts a lot of code out of the core, simplify runtime processing and make plug-in creation simpler to understand. The only think I still want to look at is how exactly menu paths are translated right now. Note that it still works, but it's possible that some things may be worth improving/simplifying on this side too. --- app/actions/plug-in-actions.c | 127 +----------- app/gimpcore.def | 3 - app/menus/plug-in-menus.c | 28 +-- app/pdb/internal-procs.c | 2 +- app/pdb/plug-in-cmds.c | 67 ------- app/plug-in/Makefile.am | 2 - app/plug-in/gimpplugin.c | 9 - app/plug-in/gimpplugindef.c | 33 --- app/plug-in/gimpplugindef.h | 6 - app/plug-in/gimppluginmanager-locale-domain.c | 189 ------------------ app/plug-in/gimppluginmanager-locale-domain.h | 44 ---- app/plug-in/gimppluginmanager-restore.c | 42 +--- app/plug-in/gimppluginmanager.c | 3 - app/plug-in/gimppluginmanager.h | 1 - app/plug-in/gimppluginprocedure.c | 47 +---- app/plug-in/gimppluginprocedure.h | 8 - app/plug-in/meson.build | 1 - app/plug-in/plug-in-rc.c | 55 ----- libgimp/gimpplugin.c | 15 -- libgimp/gimpplugin_pdb.c | 42 ---- libgimp/gimpplugin_pdb.h | 2 - pdb/groups/plug_in.pdb | 49 +---- 22 files changed, 22 insertions(+), 753 deletions(-) delete mode 100644 app/plug-in/gimppluginmanager-locale-domain.c delete mode 100644 app/plug-in/gimppluginmanager-locale-domain.h diff --git a/app/actions/plug-in-actions.c b/app/actions/plug-in-actions.c index ba10d819ff..e2435e5a5e 100644 --- a/app/actions/plug-in-actions.c +++ b/app/actions/plug-in-actions.c @@ -34,7 +34,6 @@ #include "plug-in/gimppluginmanager.h" #include "plug-in/gimppluginmanager-help-domain.h" -#include "plug-in/gimppluginmanager-locale-domain.h" #include "plug-in/gimppluginmanager-menu-branch.h" #include "plug-in/gimppluginprocedure.h" @@ -69,10 +68,7 @@ static void plug_in_actions_menu_path_added (GimpPlugInProcedure *proc, static void plug_in_actions_add_proc (GimpActionGroup *group, GimpPlugInProcedure *proc); -static gboolean plug_in_actions_check_translation (const gchar *original, - const gchar *translated); static void plug_in_actions_build_path (GimpActionGroup *group, - const gchar *original, const gchar *translated); @@ -186,30 +182,11 @@ plug_in_actions_menu_branch_added (GimpPlugInManager *manager, const gchar *menu_label, GimpActionGroup *group) { - const gchar *locale_domain = NULL; - gchar *full_translated = NULL; - gchar *full; + gchar *full; full = g_strconcat (menu_path, "/", menu_label, NULL); + plug_in_actions_build_path (group, full); - if (gimp_plug_in_manager_get_i18n (manager, file, &locale_domain, NULL)) - { - const gchar *path_translated; - const gchar *label_translated; - - path_translated = dgettext (locale_domain, menu_path); - label_translated = dgettext (locale_domain, menu_label); - - full_translated = g_strconcat (path_translated, "/", label_translated, NULL); - } - - if (full_translated != NULL && - plug_in_actions_check_translation (full, full_translated)) - plug_in_actions_build_path (group, full, full_translated); - else - plug_in_actions_build_path (group, full, full); - - g_free (full_translated); g_free (full); } @@ -276,22 +253,12 @@ plug_in_actions_menu_path_added (GimpPlugInProcedure *plug_in_proc, const gchar *menu_path, GimpActionGroup *group) { - const gchar *locale_domain = NULL; - const gchar *path_translated = NULL; - #if 0 g_print ("%s: %s (%s)\n", G_STRFUNC, gimp_object_get_name (plug_in_proc), menu_path); #endif - if (gimp_plug_in_procedure_get_i18n (plug_in_proc, &locale_domain)) - path_translated = dgettext (locale_domain, menu_path); - - if (path_translated && - plug_in_actions_check_translation (menu_path, path_translated)) - plug_in_actions_build_path (group, menu_path, path_translated); - else - plug_in_actions_build_path (group, menu_path, menu_path); + plug_in_actions_build_path (group, menu_path); } static void @@ -299,11 +266,7 @@ plug_in_actions_add_proc (GimpActionGroup *group, GimpPlugInProcedure *proc) { GimpProcedureActionEntry entry; - const gchar *locale_domain = NULL; GList *list; - gboolean localize; - - localize = gimp_plug_in_procedure_get_i18n (proc, &locale_domain); entry.name = gimp_object_get_name (proc); entry.icon_name = gimp_viewable_get_icon_name (GIMP_VIEWABLE (proc)); @@ -318,13 +281,9 @@ plug_in_actions_add_proc (GimpActionGroup *group, for (list = proc->menu_paths; list; list = g_list_next (list)) { - const gchar *original = list->data; - const gchar *translated = localize ? dgettext (locale_domain, original) : NULL; + const gchar *original = list->data; - if (translated && plug_in_actions_check_translation (original, translated)) - plug_in_actions_build_path (group, original, translated); - else - plug_in_actions_build_path (group, original, original); + plug_in_actions_build_path (group, original); } if (proc->image_types_val) @@ -351,73 +310,13 @@ plug_in_actions_add_proc (GimpActionGroup *group, } } -static gboolean -plug_in_actions_check_translation (const gchar *original, - const gchar *translated) -{ - const gchar *p1; - const gchar *p2; - - /* first check if is present and identical in both strings */ - p1 = strchr (original, '>'); - p2 = strchr (translated, '>'); - - if (!p1 || !p2 || - (p1 - original) != (p2 - translated) || - strncmp (original, translated, p1 - original)) - { - g_printerr ("bad translation \"%s\"\n" - "for menu path \"%s\"\n" - "( must not be translated)\n\n", - translated, original); - return FALSE; - } - - p1++; - p2++; - - /* then check if either a '/' or nothing follows in *both* strings */ - if (! ((*p1 == '/' && *p2 == '/') || - (*p1 == '\0' && *p2 == '\0'))) - { - g_printerr ("bad translation \"%s\"\n" - "for menu path \"%s\"\n" - "( must be followed by either nothing or '/')\n\n", - translated, original); - return FALSE; - } - - /* then check the number of slashes in the remaining string */ - while (p1 && p2) - { - p1 = strchr (p1, '/'); - p2 = strchr (p2, '/'); - - if (p1) p1++; - if (p2) p2++; - } - - if (p1 || p2) - { - g_printerr ("bad translation \"%s\"\n" - "for menu path \"%s\"\n" - "(number of '/' must be the same)\n\n", - translated, original); - return FALSE; - } - - return TRUE; -} - static void plug_in_actions_build_path (GimpActionGroup *group, - const gchar *path_original, const gchar *path_translated) { GHashTable *path_table; - gchar *copy_original; gchar *copy_translated; - gchar *p1, *p2; + gchar *p2; path_table = g_object_get_data (G_OBJECT (group), "plug-in-path-table"); @@ -431,13 +330,11 @@ plug_in_actions_build_path (GimpActionGroup *group, (GDestroyNotify) g_hash_table_destroy); } - copy_original = gimp_strip_uline (path_original); copy_translated = g_strdup (path_translated); - p1 = strrchr (copy_original, '/'); p2 = strrchr (copy_translated, '/'); - if (p1 && p2 && ! g_hash_table_lookup (path_table, copy_original)) + if (p2 && ! g_hash_table_lookup (path_table, copy_translated)) { GimpAction *action; gchar *label; @@ -446,22 +343,20 @@ plug_in_actions_build_path (GimpActionGroup *group, #if 0 g_print ("adding plug-in submenu '%s' (%s)\n", - copy_original, label); + copy_translated, label); #endif - action = gimp_action_impl_new (copy_original, label, NULL, NULL, NULL); + action = gimp_action_impl_new (copy_translated, label, NULL, NULL, NULL); gimp_action_group_add_action (group, action); g_object_unref (action); - g_hash_table_insert (path_table, g_strdup (copy_original), action); + g_hash_table_insert (path_table, g_strdup (copy_translated), action); - *p1 = '\0'; *p2 = '\0'; /* recursively call ourselves with the last part of the path removed */ - plug_in_actions_build_path (group, copy_original, copy_translated); + plug_in_actions_build_path (group, copy_translated); } - g_free (copy_original); g_free (copy_translated); } diff --git a/app/gimpcore.def b/app/gimpcore.def index 12d4d58494..09e9228598 100644 --- a/app/gimpcore.def +++ b/app/gimpcore.def @@ -738,7 +738,6 @@ gimp_pickable_get_tiles gimp_plug_in_manager_data_free gimp_plug_in_manager_get_help_domain gimp_plug_in_manager_get_help_domains -gimp_plug_in_manager_get_i18n gimp_procedure_execute_async gimp_procedure_get_arguments gimp_procedure_get_type @@ -774,7 +773,6 @@ gimp_plug_in_procedure_get_label gimp_plug_in_procedure_get_type gimp_plug_in_procedure_new gimp_plug_in_procedure_set_file_proc -gimp_plug_in_procedure_set_i18n gimp_plug_in_procedure_set_icon gimp_plug_in_procedure_set_image_types gimp_plug_in_procedure_set_mime_type @@ -834,7 +832,6 @@ gimp_message_valist gimp_viewable_set_stock_id gimp_plug_in_procedure_get_blurb -gimp_plug_in_procedure_get_i18n gimp_channel_select_round_rect gimp_drawable_undo_get_type diff --git a/app/menus/plug-in-menus.c b/app/menus/plug-in-menus.c index 8d89634b39..e4ec8531e9 100644 --- a/app/menus/plug-in-menus.c +++ b/app/menus/plug-in-menus.c @@ -31,7 +31,6 @@ #include "core/gimp.h" #include "plug-in/gimppluginmanager.h" -#include "plug-in/gimppluginmanager-locale-domain.h" #include "plug-in/gimppluginprocedure.h" #include "widgets/gimpuimanager.h" @@ -137,14 +136,7 @@ plug_in_menus_setup (GimpUIManager *manager, if (plug_in_proc->menu_label && ! plug_in_proc->file_proc) { - GFile *file = gimp_plug_in_procedure_get_file (plug_in_proc); - GList *path; - const gchar *locale_domain = NULL; - gboolean localize; - - localize = - gimp_plug_in_manager_get_i18n (plug_in_manager, - file, &locale_domain, NULL); + GList *path; for (path = plug_in_proc->menu_paths; path; path = g_list_next (path)) { @@ -156,21 +148,9 @@ plug_in_menus_setup (GimpUIManager *manager, entry->proc = plug_in_proc; entry->menu_path = path->data; - if (localize) - { - menu = g_strconcat (dgettext (locale_domain, - path->data), - "/", - dgettext (locale_domain, - plug_in_proc->menu_label), - NULL); - } - else - { - menu = g_strconcat (path->data, "/", - plug_in_proc->menu_label, - NULL); - } + menu = g_strconcat (path->data, "/", + plug_in_proc->menu_label, + NULL); plug_in_menus_tree_insert (menu_entries, menu, entry); g_free (menu); diff --git a/app/pdb/internal-procs.c b/app/pdb/internal-procs.c index 1fa6c26fde..67aeef98ff 100644 --- a/app/pdb/internal-procs.c +++ b/app/pdb/internal-procs.c @@ -30,7 +30,7 @@ #include "internal-procs.h" -/* 765 procedures registered total */ +/* 764 procedures registered total */ void internal_procs_init (GimpPDB *pdb) diff --git a/app/pdb/plug-in-cmds.c b/app/pdb/plug-in-cmds.c index 2e5efd9b6c..35652bf2fa 100644 --- a/app/pdb/plug-in-cmds.c +++ b/app/pdb/plug-in-cmds.c @@ -85,42 +85,6 @@ plug_ins_query_invoker (GimpProcedure *procedure, return return_vals; } -static GimpValueArray * -plug_in_domain_register_invoker (GimpProcedure *procedure, - Gimp *gimp, - GimpContext *context, - GimpProgress *progress, - const GimpValueArray *args, - GError **error) -{ - gboolean success = TRUE; - const gchar *domain_name; - GFile *domain_file; - - domain_name = g_value_get_string (gimp_value_array_index (args, 0)); - domain_file = g_value_get_object (gimp_value_array_index (args, 1)); - - if (success) - { - GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in; - - if (plug_in && plug_in->call_mode == GIMP_PLUG_IN_CALL_QUERY) - { - gchar *domain_path = domain_file ? g_file_get_path (domain_file) : NULL; - - gimp_plug_in_def_set_locale_domain (plug_in->plug_in_def, - domain_name, domain_path); - - g_free (domain_path); - } - else - success = FALSE; - } - - return gimp_procedure_get_return_values (procedure, success, - error ? *error : NULL); -} - static GimpValueArray * plug_in_help_register_invoker (GimpProcedure *procedure, Gimp *gimp, @@ -306,37 +270,6 @@ register_plug_in_procs (GimpPDB *pdb) gimp_pdb_register_procedure (pdb, procedure); g_object_unref (procedure); - /* - * gimp-plug-in-domain-register - */ - procedure = gimp_procedure_new (plug_in_domain_register_invoker); - gimp_object_set_static_name (GIMP_OBJECT (procedure), - "gimp-plug-in-domain-register"); - gimp_procedure_set_static_help (procedure, - "Registers a textdomain for localisation.", - "This procedure adds a textdomain to the list of domains GIMP searches for strings when translating its menu entries.\n" - "Only core plug-ins should call this function directly. Third-party plug-ins are expected instead to define a custom `set_i18n()` method returning their domain and a path relative to their folder. In other words, this should be considered an internal PDB function which should not be used except by core developers.", - NULL); - gimp_procedure_set_static_attribution (procedure, - "Sven Neumann ", - "Sven Neumann", - "2000"); - gimp_procedure_add_argument (procedure, - gimp_param_spec_string ("domain-name", - "domain name", - "The name of the textdomain (must be unique)", - FALSE, FALSE, FALSE, - NULL, - GIMP_PARAM_READWRITE)); - gimp_procedure_add_argument (procedure, - g_param_spec_object ("domain-file", - "domain file", - "The path to the locally installed compiled message catalog (may be NULL)", - G_TYPE_FILE, - GIMP_PARAM_READWRITE)); - gimp_pdb_register_procedure (pdb, procedure); - g_object_unref (procedure); - /* * gimp-plug-in-help-register */ diff --git a/app/plug-in/Makefile.am b/app/plug-in/Makefile.am index 4e036d68bd..f6b4f43014 100644 --- a/app/plug-in/Makefile.am +++ b/app/plug-in/Makefile.am @@ -51,8 +51,6 @@ libappplug_in_a_SOURCES = \ gimppluginmanager-file.h \ gimppluginmanager-help-domain.c \ gimppluginmanager-help-domain.h \ - gimppluginmanager-locale-domain.c \ - gimppluginmanager-locale-domain.h \ gimppluginmanager-menu-branch.c \ gimppluginmanager-menu-branch.h \ gimppluginmanager-query.c \ diff --git a/app/plug-in/gimpplugin.c b/app/plug-in/gimpplugin.c index 9040f5ddc4..4e46a8ea7c 100644 --- a/app/plug-in/gimpplugin.c +++ b/app/plug-in/gimpplugin.c @@ -89,7 +89,6 @@ #include "gimpplugindef.h" #include "gimppluginmanager.h" #include "gimppluginmanager-help-domain.h" -#include "gimppluginmanager-locale-domain.h" #include "gimptemporaryprocedure.h" #include "gimp-intl.h" @@ -927,8 +926,6 @@ gimp_plug_in_add_temp_proc (GimpPlugIn *plug_in, { GimpPlugInProcedure *overridden; const gchar *help_domain; - const gchar *locale_domain = NULL; - gboolean localize; g_return_if_fail (GIMP_IS_PLUG_IN (plug_in)); g_return_if_fail (GIMP_IS_TEMPORARY_PROCEDURE (proc)); @@ -940,16 +937,10 @@ gimp_plug_in_add_temp_proc (GimpPlugIn *plug_in, gimp_plug_in_remove_temp_proc (plug_in, GIMP_TEMPORARY_PROCEDURE (overridden)); - localize = gimp_plug_in_manager_get_i18n (plug_in->manager, - plug_in->file, - &locale_domain, - NULL); help_domain = gimp_plug_in_manager_get_help_domain (plug_in->manager, plug_in->file, NULL); - gimp_plug_in_procedure_set_i18n (GIMP_PLUG_IN_PROCEDURE (proc), localize, - locale_domain); gimp_plug_in_procedure_set_help_domain (GIMP_PLUG_IN_PROCEDURE (proc), help_domain); diff --git a/app/plug-in/gimpplugindef.c b/app/plug-in/gimpplugindef.c index 4725bd9c94..e9088476c6 100644 --- a/app/plug-in/gimpplugindef.c +++ b/app/plug-in/gimpplugindef.c @@ -63,8 +63,6 @@ gimp_plug_in_def_finalize (GObject *object) GimpPlugInDef *plug_in_def = GIMP_PLUG_IN_DEF (object); g_object_unref (plug_in_def->file); - g_free (plug_in_def->locale_domain_name); - g_free (plug_in_def->locale_domain_path); g_free (plug_in_def->help_domain_name); g_free (plug_in_def->help_domain_uri); @@ -81,8 +79,6 @@ gimp_plug_in_def_get_memsize (GimpObject *object, gint64 memsize = 0; memsize += gimp_g_object_get_memsize (G_OBJECT (plug_in_def->file)); - memsize += gimp_string_get_memsize (plug_in_def->locale_domain_name); - memsize += gimp_string_get_memsize (plug_in_def->locale_domain_path); memsize += gimp_string_get_memsize (plug_in_def->help_domain_name); memsize += gimp_string_get_memsize (plug_in_def->help_domain_uri); @@ -126,9 +122,6 @@ gimp_plug_in_def_add_procedure (GimpPlugInDef *plug_in_def, proc->mtime = plug_in_def->mtime; - if (plug_in_def->locale_domain_name) - gimp_plug_in_procedure_set_i18n (proc, TRUE, - plug_in_def->locale_domain_name); gimp_plug_in_procedure_set_help_domain (proc, plug_in_def->help_domain_name); @@ -147,32 +140,6 @@ gimp_plug_in_def_remove_procedure (GimpPlugInDef *plug_in_def, g_object_unref (proc); } -void -gimp_plug_in_def_set_locale_domain (GimpPlugInDef *plug_in_def, - const gchar *domain_name, - const gchar *domain_path) -{ - GSList *list; - - g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def)); - - if (plug_in_def->locale_domain_name) - g_free (plug_in_def->locale_domain_name); - plug_in_def->locale_domain_name = g_strdup (domain_name); - - if (plug_in_def->locale_domain_path) - g_free (plug_in_def->locale_domain_path); - plug_in_def->locale_domain_path = g_strdup (domain_path); - - for (list = plug_in_def->procedures; list; list = g_slist_next (list)) - { - GimpPlugInProcedure *procedure = list->data; - - gimp_plug_in_procedure_set_i18n (procedure, TRUE, - plug_in_def->locale_domain_name); - } -} - void gimp_plug_in_def_set_help_domain (GimpPlugInDef *plug_in_def, const gchar *domain_name, diff --git a/app/plug-in/gimpplugindef.h b/app/plug-in/gimpplugindef.h index d819e1ae6a..81e55ca65e 100644 --- a/app/plug-in/gimpplugindef.h +++ b/app/plug-in/gimpplugindef.h @@ -39,8 +39,6 @@ struct _GimpPlugInDef GFile *file; GSList *procedures; - gchar *locale_domain_name; - gchar *locale_domain_path; gchar *help_domain_name; gchar *help_domain_uri; gint64 mtime; @@ -63,10 +61,6 @@ void gimp_plug_in_def_add_procedure (GimpPlugInDef *plug_in_def, void gimp_plug_in_def_remove_procedure (GimpPlugInDef *plug_in_def, GimpPlugInProcedure *proc); -void gimp_plug_in_def_set_locale_domain (GimpPlugInDef *plug_in_def, - const gchar *domain_name, - const gchar *domain_path); - void gimp_plug_in_def_set_help_domain (GimpPlugInDef *plug_in_def, const gchar *domain_name, const gchar *domain_uri); diff --git a/app/plug-in/gimppluginmanager-locale-domain.c b/app/plug-in/gimppluginmanager-locale-domain.c deleted file mode 100644 index 33c187b59f..0000000000 --- a/app/plug-in/gimppluginmanager-locale-domain.c +++ /dev/null @@ -1,189 +0,0 @@ -/* GIMP - The GNU Image Manipulation Program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * gimppluginmanager-locale-domain.c - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "config.h" - -#include - -#include - -#include "libgimpbase/gimpbase.h" - -#include "plug-in-types.h" - -#include "gimppluginmanager.h" -#include "gimppluginmanager-locale-domain.h" - - -#define STD_PLUG_INS_LOCALE_DOMAIN GETTEXT_PACKAGE "-std-plug-ins" - - -typedef struct _GimpPlugInLocaleDomain GimpPlugInLocaleDomain; - -struct _GimpPlugInLocaleDomain -{ - GFile *file; - gchar *domain_name; - gchar *domain_path; -}; - - -void -gimp_plug_in_manager_locale_domain_exit (GimpPlugInManager *manager) -{ - GSList *list; - - g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager)); - - for (list = manager->locale_domains; list; list = list->next) - { - GimpPlugInLocaleDomain *domain = list->data; - - g_object_unref (domain->file); - g_free (domain->domain_name); - g_free (domain->domain_path); - g_slice_free (GimpPlugInLocaleDomain, domain); - } - - g_slist_free (manager->locale_domains); - manager->locale_domains = NULL; -} - -void -gimp_plug_in_manager_add_locale_domain (GimpPlugInManager *manager, - GFile *file, - const gchar *domain_name, - const gchar *domain_path) -{ - GimpPlugInLocaleDomain *domain; - - g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager)); - g_return_if_fail (G_IS_FILE (file)); - g_return_if_fail (domain_name != NULL); - - domain = g_slice_new (GimpPlugInLocaleDomain); - - domain->file = g_object_ref (file); - domain->domain_name = g_strdup (domain_name); - domain->domain_path = g_strdup (domain_path); - - manager->locale_domains = g_slist_prepend (manager->locale_domains, domain); - -#ifdef VERBOSE - g_print ("added locale domain \"%s\" for path \"%s\"\n", - domain->domain_name ? domain->domain_name : "(null)", - domain->domain_path ? - gimp_filename_to_utf8 (domain->domain_path) : "(null)"); -#endif -} - -gboolean -gimp_plug_in_manager_get_i18n (GimpPlugInManager *manager, - GFile *file, - const gchar **locale_domain, - const gchar **domain_path) -{ - GSList *list; - - g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), FALSE); - g_return_val_if_fail (file == NULL || G_IS_FILE (file), FALSE); - - if (domain_path) - *domain_path = gimp_locale_directory (); - - /* A NULL prog_name is GIMP itself, return the default domain */ - if (! file) - { - if (locale_domain) - *locale_domain = NULL; - - return TRUE; - } - - for (list = manager->locale_domains; list; list = list->next) - { - GimpPlugInLocaleDomain *domain = list->data; - - if (domain && domain->file && - g_file_equal (domain->file, file)) - { - if (domain_path && domain->domain_path) - *domain_path = domain->domain_path; - - if (locale_domain) - *locale_domain = domain->domain_name; - - return TRUE; - } - } - - return FALSE; -} - -gint -gimp_plug_in_manager_get_locale_domains (GimpPlugInManager *manager, - gchar ***locale_domains, - gchar ***locale_paths) -{ - GSList *list; - GSList *unique = NULL; - gint n_domains; - gint i; - - g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), 0); - g_return_val_if_fail (locale_domains != NULL, 0); - g_return_val_if_fail (locale_paths != NULL, 0); - - for (list = manager->locale_domains; list; list = list->next) - { - GimpPlugInLocaleDomain *domain = list->data; - GSList *tmp; - - for (tmp = unique; tmp; tmp = tmp->next) - if (! strcmp (domain->domain_name, (const gchar *) tmp->data)) - break; - - if (! tmp) - unique = g_slist_prepend (unique, domain); - } - - unique = g_slist_reverse (unique); - - n_domains = g_slist_length (unique) + 1; - - *locale_domains = g_new0 (gchar *, n_domains + 1); - *locale_paths = g_new0 (gchar *, n_domains + 1); - - (*locale_domains)[0] = g_strdup (STD_PLUG_INS_LOCALE_DOMAIN); - (*locale_paths)[0] = g_strdup (gimp_locale_directory ()); - - for (list = unique, i = 1; list; list = list->next, i++) - { - GimpPlugInLocaleDomain *domain = list->data; - - (*locale_domains)[i] = g_strdup (domain->domain_name); - (*locale_paths)[i] = (domain->domain_path ? - g_strdup (domain->domain_path) : - g_strdup (gimp_locale_directory ())); - } - - g_slist_free (unique); - - return n_domains; -} diff --git a/app/plug-in/gimppluginmanager-locale-domain.h b/app/plug-in/gimppluginmanager-locale-domain.h deleted file mode 100644 index 2d35e3683d..0000000000 --- a/app/plug-in/gimppluginmanager-locale-domain.h +++ /dev/null @@ -1,44 +0,0 @@ -/* GIMP - The GNU Image Manipulation Program - * Copyright (C) 1995 Spencer Kimball and Peter Mattis - * - * gimppluginmanager-locale-domain.h - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef __GIMP_PLUG_IN_MANAGER_LOCALE_DOMAIN_H__ -#define __GIMP_PLUG_IN_MANAGER_LOCALE_DOMAIN_H__ - - -void gimp_plug_in_manager_locale_domain_exit (GimpPlugInManager *manager); - -/* Add a locale domain */ -void gimp_plug_in_manager_add_locale_domain (GimpPlugInManager *manager, - GFile *file, - const gchar *domain_name, - const gchar *domain_path); - -/* Retrieve a plug-ins locale domain */ -gboolean gimp_plug_in_manager_get_i18n (GimpPlugInManager *manager, - GFile *file, - const gchar **locale_domain, - const gchar **locale_path); - -/* Retrieve all locale domains */ -gint gimp_plug_in_manager_get_locale_domains (GimpPlugInManager *manager, - gchar ***locale_domains, - gchar ***locale_paths); - - -#endif /* __GIMP_PLUG_IN_MANAGER_LOCALE_DOMAIN_H__ */ diff --git a/app/plug-in/gimppluginmanager-restore.c b/app/plug-in/gimppluginmanager-restore.c index 80cd23a5fb..6ac77f1c8e 100644 --- a/app/plug-in/gimppluginmanager-restore.c +++ b/app/plug-in/gimppluginmanager-restore.c @@ -44,7 +44,6 @@ #include "gimppluginmanager-call.h" #include "gimppluginmanager-file.h" #include "gimppluginmanager-help-domain.h" -#include "gimppluginmanager-locale-domain.h" #include "gimppluginmanager-restore.h" #include "gimppluginprocedure.h" #include "plug-in-rc.h" @@ -69,7 +68,6 @@ static void gimp_plug_in_manager_init_plug_ins (GimpPlugInManager *man static void gimp_plug_in_manager_run_extensions (GimpPlugInManager *manager, GimpContext *context, GimpInitStatusFunc status_callback); -static void gimp_plug_in_manager_bind_text_domains (GimpPlugInManager *manager); static void gimp_plug_in_manager_add_from_file (GimpPlugInManager *manager, GFile *file, guint64 mtime); @@ -148,19 +146,10 @@ gimp_plug_in_manager_restore (GimpPlugInManager *manager, g_object_unref (pluginrc); - /* create locale and help domain lists */ + /* create help domain lists */ for (list = manager->plug_in_defs; list; list = list->next) { - GimpPlugInDef *plug_in_def = list->data; - const gchar *locale_domain = NULL; - - if (plug_in_def->locale_domain_name) - { - gimp_plug_in_manager_add_locale_domain (manager, - plug_in_def->file, - plug_in_def->locale_domain_name, - plug_in_def->locale_domain_path); - } + GimpPlugInDef *plug_in_def = list->data; if (plug_in_def->help_domain_name) gimp_plug_in_manager_add_help_domain (manager, @@ -173,9 +162,6 @@ gimp_plug_in_manager_restore (GimpPlugInManager *manager, g_slist_free_full (manager->plug_in_defs, (GDestroyNotify) g_object_unref); manager->plug_in_defs = NULL; - /* bind plug-in text domains */ - gimp_plug_in_manager_bind_text_domains (manager); - /* add the plug-in procs to the procedure database */ for (list = manager->plug_in_procedures; list; list = list->next) { @@ -642,30 +628,6 @@ gimp_plug_in_manager_run_extensions (GimpPlugInManager *manager, } } -static void -gimp_plug_in_manager_bind_text_domains (GimpPlugInManager *manager) -{ - gchar **locale_domains; - gchar **locale_paths; - gint n_domains; - gint i; - - n_domains = gimp_plug_in_manager_get_locale_domains (manager, - &locale_domains, - &locale_paths); - - for (i = 0; i < n_domains; i++) - { - bindtextdomain (locale_domains[i], locale_paths[i]); -#ifdef HAVE_BIND_TEXTDOMAIN_CODESET - bind_textdomain_codeset (locale_domains[i], "UTF-8"); -#endif - } - - g_strfreev (locale_domains); - g_strfreev (locale_paths); -} - /** * gimp_plug_in_manager_ignore_plugin_basename: * @basename: Basename to test with diff --git a/app/plug-in/gimppluginmanager.c b/app/plug-in/gimppluginmanager.c index 31b86e1cde..46d534c5d3 100644 --- a/app/plug-in/gimppluginmanager.c +++ b/app/plug-in/gimppluginmanager.c @@ -46,7 +46,6 @@ #include "gimppluginmanager.h" #include "gimppluginmanager-data.h" #include "gimppluginmanager-help-domain.h" -#include "gimppluginmanager-locale-domain.h" #include "gimppluginmanager-menu-branch.h" #include "gimppluginshm.h" #include "gimptemporaryprocedure.h" @@ -161,7 +160,6 @@ gimp_plug_in_manager_finalize (GObject *object) g_clear_pointer (&manager->debug, gimp_plug_in_debug_free); gimp_plug_in_manager_menu_branch_exit (manager); - gimp_plug_in_manager_locale_domain_exit (manager); gimp_plug_in_manager_help_domain_exit (manager); gimp_plug_in_manager_data_free (manager); @@ -192,7 +190,6 @@ gimp_plug_in_manager_get_memsize (GimpObject *object, memsize += gimp_g_slist_get_memsize (manager->display_raw_load_procs, 0); memsize += gimp_g_slist_get_memsize (manager->menu_branches, 0 /* FIXME */); - memsize += gimp_g_slist_get_memsize (manager->locale_domains, 0 /* FIXME */); memsize += gimp_g_slist_get_memsize (manager->help_domains, 0 /* FIXME */); memsize += gimp_g_slist_get_memsize_foreach (manager->open_plug_ins, diff --git a/app/plug-in/gimppluginmanager.h b/app/plug-in/gimppluginmanager.h index 18328e3750..cd153c215a 100644 --- a/app/plug-in/gimppluginmanager.h +++ b/app/plug-in/gimppluginmanager.h @@ -56,7 +56,6 @@ struct _GimpPlugInManager GSList *display_raw_load_procs; GSList *menu_branches; - GSList *locale_domains; GSList *help_domains; GimpPlugIn *current_plug_in; diff --git a/app/plug-in/gimppluginprocedure.c b/app/plug-in/gimppluginprocedure.c index f30e945c5a..03346f728a 100644 --- a/app/plug-in/gimppluginprocedure.c +++ b/app/plug-in/gimppluginprocedure.c @@ -255,14 +255,7 @@ gimp_plug_in_procedure_get_menu_label (GimpProcedure *procedure) GimpPlugInProcedure *proc = GIMP_PLUG_IN_PROCEDURE (procedure); if (proc->menu_label) - { - const gchar *locale_domain = NULL; - - if (gimp_plug_in_procedure_get_i18n (proc, &locale_domain)) - return dgettext (locale_domain, proc->menu_label); - else - return proc->menu_label; - } + return proc->menu_label; return GIMP_PROCEDURE_CLASS (parent_class)->get_menu_label (procedure); } @@ -270,18 +263,8 @@ gimp_plug_in_procedure_get_menu_label (GimpProcedure *procedure) static const gchar * gimp_plug_in_procedure_get_blurb (GimpProcedure *procedure) { - GimpPlugInProcedure *proc = GIMP_PLUG_IN_PROCEDURE (procedure); - - /* do not to pass the empty string to gettext() */ - if (procedure->blurb && strlen (procedure->blurb)) - { - const gchar *locale_domain = NULL; - - if (gimp_plug_in_procedure_get_i18n (proc, &locale_domain)) - return dgettext (locale_domain, procedure->blurb); - else - return procedure->blurb; - } + if (procedure->blurb) + return procedure->blurb; return NULL; } @@ -571,30 +554,6 @@ gimp_plug_in_procedure_get_file (GimpPlugInProcedure *proc) return GIMP_PLUG_IN_PROCEDURE_GET_CLASS (proc)->get_file (proc); } -void -gimp_plug_in_procedure_set_i18n (GimpPlugInProcedure *proc, - gboolean localize, - const gchar *locale_domain) -{ - g_return_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc)); - - proc->localize = localize; - proc->locale_domain = localize && locale_domain ? g_quark_from_string (locale_domain) : 0; -} - -gboolean -gimp_plug_in_procedure_get_i18n (GimpPlugInProcedure *proc, - const gchar **domain) -{ - g_return_val_if_fail (GIMP_IS_PLUG_IN_PROCEDURE (proc), FALSE); - g_return_val_if_fail (domain && *domain == NULL, FALSE); - - if (proc->localize) - *domain = g_quark_to_string (proc->locale_domain); - - return proc->localize; -} - void gimp_plug_in_procedure_set_help_domain (GimpPlugInProcedure *proc, const gchar *help_domain) diff --git a/app/plug-in/gimppluginprocedure.h b/app/plug-in/gimppluginprocedure.h index 56fd048a99..8394bdfb71 100644 --- a/app/plug-in/gimppluginprocedure.h +++ b/app/plug-in/gimppluginprocedure.h @@ -40,8 +40,6 @@ struct _GimpPlugInProcedure /* common members */ GFile *file; - gboolean localize; - GQuark locale_domain; GQuark help_domain; gchar *menu_label; GList *menu_paths; @@ -98,12 +96,6 @@ GimpPlugInProcedure * gimp_plug_in_procedure_find (GSList *lis GFile * gimp_plug_in_procedure_get_file (GimpPlugInProcedure *proc); -void gimp_plug_in_procedure_set_i18n (GimpPlugInProcedure *proc, - gboolean localize, - const gchar *locale_domain); -gboolean gimp_plug_in_procedure_get_i18n (GimpPlugInProcedure *proc, - const gchar **domain); - void gimp_plug_in_procedure_set_help_domain (GimpPlugInProcedure *proc, const gchar *help_domain); const gchar * gimp_plug_in_procedure_get_help_domain (GimpPlugInProcedure *proc); diff --git a/app/plug-in/meson.build b/app/plug-in/meson.build index 43c9facc21..1cf44a5666 100644 --- a/app/plug-in/meson.build +++ b/app/plug-in/meson.build @@ -33,7 +33,6 @@ libappplugin_sources = [ 'gimppluginmanager-data.c', 'gimppluginmanager-file.c', 'gimppluginmanager-help-domain.c', - 'gimppluginmanager-locale-domain.c', 'gimppluginmanager-menu-branch.c', 'gimppluginmanager-query.c', 'gimppluginmanager-restore.c', diff --git a/app/plug-in/plug-in-rc.c b/app/plug-in/plug-in-rc.c index 500e6f1404..d2ead9d5da 100644 --- a/app/plug-in/plug-in-rc.c +++ b/app/plug-in/plug-in-rc.c @@ -66,8 +66,6 @@ static GTokenType plug_in_proc_arg_deserialize (GScanner *scanner, Gimp *gimp, GimpProcedure *procedure, gboolean return_value); -static GTokenType plug_in_locale_def_deserialize (GScanner *scanner, - GimpPlugInDef *plug_in_def); static GTokenType plug_in_help_def_deserialize (GScanner *scanner, GimpPlugInDef *plug_in_def); static GTokenType plug_in_has_init_deserialize (GScanner *scanner, @@ -80,7 +78,6 @@ enum FILE_VERSION, PLUG_IN_DEF, PROC_DEF, - LOCALE_DEF, HELP_DEF, HAS_INIT, PROC_ARG, @@ -134,8 +131,6 @@ plug_in_rc_parse (Gimp *gimp, g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF, "proc-def", GINT_TO_POINTER (PROC_DEF)); - g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF, - "locale-def", GINT_TO_POINTER (LOCALE_DEF)); g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF, "help-def", GINT_TO_POINTER (HELP_DEF)); g_scanner_scope_add_symbol (scanner, PLUG_IN_DEF, @@ -337,10 +332,6 @@ plug_in_def_deserialize (Gimp *gimp, g_object_unref (proc); break; - case LOCALE_DEF: - token = plug_in_locale_def_deserialize (scanner, plug_in_def); - break; - case HELP_DEF: token = plug_in_help_def_deserialize (scanner, plug_in_def); break; @@ -957,32 +948,6 @@ plug_in_proc_arg_deserialize (GScanner *scanner, return token; } -static GTokenType -plug_in_locale_def_deserialize (GScanner *scanner, - GimpPlugInDef *plug_in_def) -{ - gchar *domain_name; - gchar *domain_path = NULL; - gchar *expanded_path = NULL; - - if (! gimp_scanner_parse_string (scanner, &domain_name)) - return G_TOKEN_STRING; - - if (gimp_scanner_parse_string (scanner, &domain_path)) - expanded_path = gimp_config_path_expand (domain_path, TRUE, NULL); - - gimp_plug_in_def_set_locale_domain (plug_in_def, domain_name, expanded_path); - - g_free (domain_name); - g_free (domain_path); - g_free (expanded_path); - - if (! gimp_scanner_parse_token (scanner, G_TOKEN_RIGHT_PAREN)) - return G_TOKEN_RIGHT_PAREN; - - return G_TOKEN_LEFT_PAREN; -} - static GTokenType plug_in_help_def_deserialize (GScanner *scanner, GimpPlugInDef *plug_in_def) @@ -1335,26 +1300,6 @@ plug_in_rc_write (GSList *plug_in_defs, gimp_config_writer_close (writer); } - if (plug_in_def->locale_domain_name) - { - gimp_config_writer_open (writer, "locale-def"); - gimp_config_writer_string (writer, - plug_in_def->locale_domain_name); - - if (plug_in_def->locale_domain_path) - { - path = gimp_config_path_unexpand (plug_in_def->locale_domain_path, - TRUE, NULL); - if (path) - { - gimp_config_writer_string (writer, path); - g_free (path); - } - } - - gimp_config_writer_close (writer); - } - if (plug_in_def->help_domain_name) { gimp_config_writer_open (writer, "help-def"); diff --git a/libgimp/gimpplugin.c b/libgimp/gimpplugin.c index bf84bc1d83..08baa91837 100644 --- a/libgimp/gimpplugin.c +++ b/libgimp/gimpplugin.c @@ -1046,26 +1046,11 @@ gimp_plug_in_register (GimpPlugIn *plug_in, { const gchar *name = list->data; GimpProcedure *procedure; - gchar *gettext_domain = NULL; - gchar *catalog_dir = NULL; procedure = _gimp_plug_in_create_procedure (plug_in, name); if (procedure) { GIMP_PROCEDURE_GET_CLASS (procedure)->install (procedure); - - if (_gimp_plug_in_set_i18n (plug_in, gimp_procedure_get_name (procedure), - &gettext_domain, &catalog_dir)) - { - GFile *file = g_file_new_for_path (catalog_dir); - - _gimp_plug_in_domain_register (gettext_domain, file); - - g_free (gettext_domain); - g_free (catalog_dir); - g_object_unref (file); - } - g_object_unref (procedure); } else diff --git a/libgimp/gimpplugin_pdb.c b/libgimp/gimpplugin_pdb.c index 9e98bdc55d..0fc5043a1c 100644 --- a/libgimp/gimpplugin_pdb.c +++ b/libgimp/gimpplugin_pdb.c @@ -27,48 +27,6 @@ #include "gimp.h" #include "gimpplugin_pdb.h" -/** - * _gimp_plug_in_domain_register: - * @domain_name: The name of the textdomain (must be unique). - * @domain_file: The path to the locally installed compiled message catalog (may be NULL). - * - * Registers a textdomain for localisation. - * - * This procedure adds a textdomain to the list of domains GIMP - * searches for strings when translating its menu entries. - * Only core plug-ins should call this function directly. Third-party - * plug-ins are expected instead to define a custom `set_i18n()` method - * returning their domain and a path relative to their folder. In other - * words, this should be considered an internal PDB function which - * should not be used except by core developers. - * - * Returns: TRUE on success. - **/ -gboolean -_gimp_plug_in_domain_register (const gchar *domain_name, - GFile *domain_file) -{ - GimpValueArray *args; - GimpValueArray *return_vals; - gboolean success = TRUE; - - args = gimp_value_array_new_from_types (NULL, - G_TYPE_STRING, domain_name, - G_TYPE_FILE, domain_file, - G_TYPE_NONE); - - return_vals = gimp_pdb_run_procedure_array (gimp_get_pdb (), - "gimp-plug-in-domain-register", - args); - gimp_value_array_unref (args); - - success = GIMP_VALUES_GET_ENUM (return_vals, 0) == GIMP_PDB_SUCCESS; - - gimp_value_array_unref (return_vals); - - return success; -} - /** * _gimp_plug_in_help_register: * @domain_name: The XML namespace of the plug-in's help pages. diff --git a/libgimp/gimpplugin_pdb.h b/libgimp/gimpplugin_pdb.h index 14a95fc98a..6852ed6ffa 100644 --- a/libgimp/gimpplugin_pdb.h +++ b/libgimp/gimpplugin_pdb.h @@ -32,8 +32,6 @@ G_BEGIN_DECLS /* For information look into the C source or the html documentation */ -G_GNUC_INTERNAL gboolean _gimp_plug_in_domain_register (const gchar *domain_name, - GFile *domain_file); G_GNUC_INTERNAL gboolean _gimp_plug_in_help_register (const gchar *domain_name, GFile *domain_file); G_GNUC_INTERNAL gboolean _gimp_plug_in_menu_branch_register (const gchar *menu_path, diff --git a/pdb/groups/plug_in.pdb b/pdb/groups/plug_in.pdb index 23fb0ad40c..fe516085e1 100644 --- a/pdb/groups/plug_in.pdb +++ b/pdb/groups/plug_in.pdb @@ -57,52 +57,6 @@ CODE ); } -sub plug_in_domain_register { - $blurb = 'Registers a textdomain for localisation.'; - - $help = <<'HELP'; -This procedure adds a textdomain to the list of domains GIMP searches -for strings when translating its menu entries. - -Only core plug-ins should call this function directly. Third-party -plug-ins are expected instead to define a custom `set_i18n()` method -returning their domain and a path relative to their folder. In other -words, this should be considered an internal PDB function which should -not be used except by core developers. -HELP - - &neo_pdb_misc('2000'); - - $lib_private = 1; - - @inargs = ( - { name => 'domain_name', type => 'string', - desc => 'The name of the textdomain (must be unique)' }, - { name => 'domain_file', type => 'file', - desc => 'The path to the locally installed compiled message catalog (may be NULL)' } - ); - - %invoke = ( - code => <<'CODE' -{ - GimpPlugIn *plug_in = gimp->plug_in_manager->current_plug_in; - - if (plug_in && plug_in->call_mode == GIMP_PLUG_IN_CALL_QUERY) - { - gchar *domain_path = domain_file ? g_file_get_path (domain_file) : NULL; - - gimp_plug_in_def_set_locale_domain (plug_in->plug_in_def, - domain_name, domain_path); - - g_free (domain_path); - } - else - success = FALSE; -} -CODE - ); -} - sub plug_in_help_register { $blurb = "Register a help path for a plug-in."; @@ -270,13 +224,12 @@ CODE "gimppdb-utils.h"); @procs = qw(plug_ins_query - plug_in_domain_register plug_in_help_register plug_in_menu_branch_register plug_in_set_pdb_error_handler plug_in_get_pdb_error_handler); -%exports = (app => [@procs], lib => [@procs[1,2,3,4,5]]); +%exports = (app => [@procs], lib => [@procs[1,2,3,4]]); $desc = 'Plug-in';