From e477d76b486f5ed9f94ee76356d571b1bbd96d05 Mon Sep 17 00:00:00 2001 From: Sven Neumann Date: Sat, 26 Feb 2000 19:09:28 +0000 Subject: [PATCH] translate branches on the fly, get rid of dummy_entries --Sven --- ChangeLog | 23 +++++++- app/gui/menus.c | 96 ++++++++++++++++++++----------- app/menus.c | 96 ++++++++++++++++++++----------- app/menus/menus.c | 96 ++++++++++++++++++++----------- app/widgets/gimpitemfactory.c | 96 ++++++++++++++++++++----------- plug-ins/gap/gap_frontends_main.c | 8 --- plug-ins/perl/po/de.po | 4 +- plug-ins/script-fu/script-fu.c | 20 ------- plug-ins/webbrowser/webbrowser.c | 1 - 9 files changed, 272 insertions(+), 168 deletions(-) diff --git a/ChangeLog b/ChangeLog index 372fc953b2..3e8c80c33f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,26 @@ +Sat Feb 26 19:56:35 CET 2000 Sven Neumann + Daniel Egger + + * app/menus.c: Branches are now translated on the fly by using + the translation of the menu_entry that causes the menu to be + created. This has the drawback that this menu needs to have a + proper translation or the branch won't be translated, but we + don't need the dummy_entries any more and plugins can provide + deeply nested menus that are translated from one string. + + * plug-ins/gap/gap_frontends_main.c + * plug-ins/script-fu/script-fu.c + * plug-ins/webbrowser/webbrowser.c: removed the dummy entries + + The translation of Script-Fu is the remaining problem. IMHO we + should solve this properly by writing a xgettext-like script + that parses the Script-Fus and add a gimp-script-fu domain. + With trivial changes to script-fu-scripts.c we will get a + completely internationalized Script-Fu UI. + 2000-02-26 Garry R. Osgood - * app/commands.c + + * app/commands.c * app/gimpimage.c * app/layer.c * app/layer.h diff --git a/app/gui/menus.c b/app/gui/menus.c index c757eeb3ef..dd80aa7020 100644 --- a/app/gui/menus.c +++ b/app/gui/menus.c @@ -71,29 +71,6 @@ static void help_debug_cmd_callback (GtkWidget *widget, gpointer callback_data, guint callback_action); -#ifdef ENABLE_NLS - -/* from main.c */ -extern gchar *plugin_domains[]; -extern gint n_plugin_domains; - -/* for i18n */ -static gchar G_GNUC_UNUSED *dummy_entries[] = -{ - /* */ - N_("/Filters/Colors/Map"), - N_("/Filters/Render/Clouds"), - N_("/Filters/Render/Nature"), - N_("/Filters/Render/Pattern"), - N_("/Filters/Misc"), - - /* Perl-Fu */ - N_("/Xtns/Animation"), - N_("/Guides"), -}; - -#endif /* ENABLE_NLS */ - static GSList *last_opened_raw_filenames = NULL; /***** *****/ @@ -942,10 +919,8 @@ menus_create_item_from_full_path (GimpItemFactoryEntry *entry, while (p) { - g_string_assign (tearoff_path, entry->entry.path + factory_length); - g_string_truncate (tearoff_path, - p - entry->entry.path + 1 - factory_length); - g_string_append (tearoff_path, "tearoff1"); + g_string_assign (tearoff_path, path + factory_length); + g_string_truncate (tearoff_path, p - path - factory_length); if (! gtk_item_factory_get_widget (item_factory, tearoff_path->str)) @@ -956,7 +931,19 @@ menus_create_item_from_full_path (GimpItemFactoryEntry *entry, NULL, NULL }; - + GimpItemFactoryEntry branch_entry = + { + { NULL, NULL, NULL, 0, "" }, + NULL, + NULL + }; + + branch_entry.entry.path = tearoff_path->str; + gtk_object_set_data (GTK_OBJECT (item_factory), "complete", path); + menus_create_item (item_factory, &branch_entry, NULL, 2); + gtk_object_remove_data (GTK_OBJECT (item_factory), "complete"); + + g_string_append (tearoff_path, "/tearoff1"); tearoff_entry.entry.path = tearoff_path->str; menus_create_item (item_factory, &tearoff_entry, NULL, 2); } @@ -1761,6 +1748,8 @@ menu_translate (const gchar *path, gchar *factory; gchar *translation; gchar *domain = NULL; + gchar *complete = NULL; + gchar *p, *t; factory = (gchar *) data; @@ -1779,20 +1768,59 @@ menu_translate (const gchar *path, if (item_factory) domain = gtk_object_get_data (GTK_OBJECT (item_factory), "textdomain"); - if (domain) /* use the plugins textdomain */ + if (domain) /* use the plugin textdomain */ { g_free (menupath); menupath = g_strconcat (factory, path, NULL); - - translation = dgettext (domain, menupath); + + complete = gtk_object_get_data (GTK_OBJECT (item_factory), "complete"); + if (complete) + { + /* + * This is a branch, use the complete path for translation, + * then strip off entries from the end until it matches. + */ + translation = g_strdup (dgettext (domain, complete)); + complete = g_strdup (complete); + + while (*complete && *translation && strcmp (complete, menupath)) + { + p = strrchr (complete, '/'); + t = strrchr (translation, '/'); + if (p && t) + { + *p = '\0'; + *t = '\0'; + } + else + break; + } + g_free (complete); + } + else + { + translation = dgettext (domain, menupath); + } /* * Work around a bug in GTK+ prior to 1.2.7 (similar workaround below) */ - if (strncmp (factory, translation, strlen (factory)) == 0) - retval = translation + strlen (factory); + if (strncmp (factory, translation, strlen (factory)) == 0) + { + retval = translation + strlen (factory); + if (complete) + { + /* assign the result to menu_path, so it gets freed on next call */ + g_free (menupath); + menupath = translation; + } + } else - g_warning ("bad translation for menupath: %s", menupath); + { + g_warning ("bad translation for menupath: %s", menupath); + if (complete) + g_free (translation); + } } else { diff --git a/app/menus.c b/app/menus.c index c757eeb3ef..dd80aa7020 100644 --- a/app/menus.c +++ b/app/menus.c @@ -71,29 +71,6 @@ static void help_debug_cmd_callback (GtkWidget *widget, gpointer callback_data, guint callback_action); -#ifdef ENABLE_NLS - -/* from main.c */ -extern gchar *plugin_domains[]; -extern gint n_plugin_domains; - -/* for i18n */ -static gchar G_GNUC_UNUSED *dummy_entries[] = -{ - /* */ - N_("/Filters/Colors/Map"), - N_("/Filters/Render/Clouds"), - N_("/Filters/Render/Nature"), - N_("/Filters/Render/Pattern"), - N_("/Filters/Misc"), - - /* Perl-Fu */ - N_("/Xtns/Animation"), - N_("/Guides"), -}; - -#endif /* ENABLE_NLS */ - static GSList *last_opened_raw_filenames = NULL; /***** *****/ @@ -942,10 +919,8 @@ menus_create_item_from_full_path (GimpItemFactoryEntry *entry, while (p) { - g_string_assign (tearoff_path, entry->entry.path + factory_length); - g_string_truncate (tearoff_path, - p - entry->entry.path + 1 - factory_length); - g_string_append (tearoff_path, "tearoff1"); + g_string_assign (tearoff_path, path + factory_length); + g_string_truncate (tearoff_path, p - path - factory_length); if (! gtk_item_factory_get_widget (item_factory, tearoff_path->str)) @@ -956,7 +931,19 @@ menus_create_item_from_full_path (GimpItemFactoryEntry *entry, NULL, NULL }; - + GimpItemFactoryEntry branch_entry = + { + { NULL, NULL, NULL, 0, "" }, + NULL, + NULL + }; + + branch_entry.entry.path = tearoff_path->str; + gtk_object_set_data (GTK_OBJECT (item_factory), "complete", path); + menus_create_item (item_factory, &branch_entry, NULL, 2); + gtk_object_remove_data (GTK_OBJECT (item_factory), "complete"); + + g_string_append (tearoff_path, "/tearoff1"); tearoff_entry.entry.path = tearoff_path->str; menus_create_item (item_factory, &tearoff_entry, NULL, 2); } @@ -1761,6 +1748,8 @@ menu_translate (const gchar *path, gchar *factory; gchar *translation; gchar *domain = NULL; + gchar *complete = NULL; + gchar *p, *t; factory = (gchar *) data; @@ -1779,20 +1768,59 @@ menu_translate (const gchar *path, if (item_factory) domain = gtk_object_get_data (GTK_OBJECT (item_factory), "textdomain"); - if (domain) /* use the plugins textdomain */ + if (domain) /* use the plugin textdomain */ { g_free (menupath); menupath = g_strconcat (factory, path, NULL); - - translation = dgettext (domain, menupath); + + complete = gtk_object_get_data (GTK_OBJECT (item_factory), "complete"); + if (complete) + { + /* + * This is a branch, use the complete path for translation, + * then strip off entries from the end until it matches. + */ + translation = g_strdup (dgettext (domain, complete)); + complete = g_strdup (complete); + + while (*complete && *translation && strcmp (complete, menupath)) + { + p = strrchr (complete, '/'); + t = strrchr (translation, '/'); + if (p && t) + { + *p = '\0'; + *t = '\0'; + } + else + break; + } + g_free (complete); + } + else + { + translation = dgettext (domain, menupath); + } /* * Work around a bug in GTK+ prior to 1.2.7 (similar workaround below) */ - if (strncmp (factory, translation, strlen (factory)) == 0) - retval = translation + strlen (factory); + if (strncmp (factory, translation, strlen (factory)) == 0) + { + retval = translation + strlen (factory); + if (complete) + { + /* assign the result to menu_path, so it gets freed on next call */ + g_free (menupath); + menupath = translation; + } + } else - g_warning ("bad translation for menupath: %s", menupath); + { + g_warning ("bad translation for menupath: %s", menupath); + if (complete) + g_free (translation); + } } else { diff --git a/app/menus/menus.c b/app/menus/menus.c index c757eeb3ef..dd80aa7020 100644 --- a/app/menus/menus.c +++ b/app/menus/menus.c @@ -71,29 +71,6 @@ static void help_debug_cmd_callback (GtkWidget *widget, gpointer callback_data, guint callback_action); -#ifdef ENABLE_NLS - -/* from main.c */ -extern gchar *plugin_domains[]; -extern gint n_plugin_domains; - -/* for i18n */ -static gchar G_GNUC_UNUSED *dummy_entries[] = -{ - /* */ - N_("/Filters/Colors/Map"), - N_("/Filters/Render/Clouds"), - N_("/Filters/Render/Nature"), - N_("/Filters/Render/Pattern"), - N_("/Filters/Misc"), - - /* Perl-Fu */ - N_("/Xtns/Animation"), - N_("/Guides"), -}; - -#endif /* ENABLE_NLS */ - static GSList *last_opened_raw_filenames = NULL; /***** *****/ @@ -942,10 +919,8 @@ menus_create_item_from_full_path (GimpItemFactoryEntry *entry, while (p) { - g_string_assign (tearoff_path, entry->entry.path + factory_length); - g_string_truncate (tearoff_path, - p - entry->entry.path + 1 - factory_length); - g_string_append (tearoff_path, "tearoff1"); + g_string_assign (tearoff_path, path + factory_length); + g_string_truncate (tearoff_path, p - path - factory_length); if (! gtk_item_factory_get_widget (item_factory, tearoff_path->str)) @@ -956,7 +931,19 @@ menus_create_item_from_full_path (GimpItemFactoryEntry *entry, NULL, NULL }; - + GimpItemFactoryEntry branch_entry = + { + { NULL, NULL, NULL, 0, "" }, + NULL, + NULL + }; + + branch_entry.entry.path = tearoff_path->str; + gtk_object_set_data (GTK_OBJECT (item_factory), "complete", path); + menus_create_item (item_factory, &branch_entry, NULL, 2); + gtk_object_remove_data (GTK_OBJECT (item_factory), "complete"); + + g_string_append (tearoff_path, "/tearoff1"); tearoff_entry.entry.path = tearoff_path->str; menus_create_item (item_factory, &tearoff_entry, NULL, 2); } @@ -1761,6 +1748,8 @@ menu_translate (const gchar *path, gchar *factory; gchar *translation; gchar *domain = NULL; + gchar *complete = NULL; + gchar *p, *t; factory = (gchar *) data; @@ -1779,20 +1768,59 @@ menu_translate (const gchar *path, if (item_factory) domain = gtk_object_get_data (GTK_OBJECT (item_factory), "textdomain"); - if (domain) /* use the plugins textdomain */ + if (domain) /* use the plugin textdomain */ { g_free (menupath); menupath = g_strconcat (factory, path, NULL); - - translation = dgettext (domain, menupath); + + complete = gtk_object_get_data (GTK_OBJECT (item_factory), "complete"); + if (complete) + { + /* + * This is a branch, use the complete path for translation, + * then strip off entries from the end until it matches. + */ + translation = g_strdup (dgettext (domain, complete)); + complete = g_strdup (complete); + + while (*complete && *translation && strcmp (complete, menupath)) + { + p = strrchr (complete, '/'); + t = strrchr (translation, '/'); + if (p && t) + { + *p = '\0'; + *t = '\0'; + } + else + break; + } + g_free (complete); + } + else + { + translation = dgettext (domain, menupath); + } /* * Work around a bug in GTK+ prior to 1.2.7 (similar workaround below) */ - if (strncmp (factory, translation, strlen (factory)) == 0) - retval = translation + strlen (factory); + if (strncmp (factory, translation, strlen (factory)) == 0) + { + retval = translation + strlen (factory); + if (complete) + { + /* assign the result to menu_path, so it gets freed on next call */ + g_free (menupath); + menupath = translation; + } + } else - g_warning ("bad translation for menupath: %s", menupath); + { + g_warning ("bad translation for menupath: %s", menupath); + if (complete) + g_free (translation); + } } else { diff --git a/app/widgets/gimpitemfactory.c b/app/widgets/gimpitemfactory.c index c757eeb3ef..dd80aa7020 100644 --- a/app/widgets/gimpitemfactory.c +++ b/app/widgets/gimpitemfactory.c @@ -71,29 +71,6 @@ static void help_debug_cmd_callback (GtkWidget *widget, gpointer callback_data, guint callback_action); -#ifdef ENABLE_NLS - -/* from main.c */ -extern gchar *plugin_domains[]; -extern gint n_plugin_domains; - -/* for i18n */ -static gchar G_GNUC_UNUSED *dummy_entries[] = -{ - /* */ - N_("/Filters/Colors/Map"), - N_("/Filters/Render/Clouds"), - N_("/Filters/Render/Nature"), - N_("/Filters/Render/Pattern"), - N_("/Filters/Misc"), - - /* Perl-Fu */ - N_("/Xtns/Animation"), - N_("/Guides"), -}; - -#endif /* ENABLE_NLS */ - static GSList *last_opened_raw_filenames = NULL; /***** *****/ @@ -942,10 +919,8 @@ menus_create_item_from_full_path (GimpItemFactoryEntry *entry, while (p) { - g_string_assign (tearoff_path, entry->entry.path + factory_length); - g_string_truncate (tearoff_path, - p - entry->entry.path + 1 - factory_length); - g_string_append (tearoff_path, "tearoff1"); + g_string_assign (tearoff_path, path + factory_length); + g_string_truncate (tearoff_path, p - path - factory_length); if (! gtk_item_factory_get_widget (item_factory, tearoff_path->str)) @@ -956,7 +931,19 @@ menus_create_item_from_full_path (GimpItemFactoryEntry *entry, NULL, NULL }; - + GimpItemFactoryEntry branch_entry = + { + { NULL, NULL, NULL, 0, "" }, + NULL, + NULL + }; + + branch_entry.entry.path = tearoff_path->str; + gtk_object_set_data (GTK_OBJECT (item_factory), "complete", path); + menus_create_item (item_factory, &branch_entry, NULL, 2); + gtk_object_remove_data (GTK_OBJECT (item_factory), "complete"); + + g_string_append (tearoff_path, "/tearoff1"); tearoff_entry.entry.path = tearoff_path->str; menus_create_item (item_factory, &tearoff_entry, NULL, 2); } @@ -1761,6 +1748,8 @@ menu_translate (const gchar *path, gchar *factory; gchar *translation; gchar *domain = NULL; + gchar *complete = NULL; + gchar *p, *t; factory = (gchar *) data; @@ -1779,20 +1768,59 @@ menu_translate (const gchar *path, if (item_factory) domain = gtk_object_get_data (GTK_OBJECT (item_factory), "textdomain"); - if (domain) /* use the plugins textdomain */ + if (domain) /* use the plugin textdomain */ { g_free (menupath); menupath = g_strconcat (factory, path, NULL); - - translation = dgettext (domain, menupath); + + complete = gtk_object_get_data (GTK_OBJECT (item_factory), "complete"); + if (complete) + { + /* + * This is a branch, use the complete path for translation, + * then strip off entries from the end until it matches. + */ + translation = g_strdup (dgettext (domain, complete)); + complete = g_strdup (complete); + + while (*complete && *translation && strcmp (complete, menupath)) + { + p = strrchr (complete, '/'); + t = strrchr (translation, '/'); + if (p && t) + { + *p = '\0'; + *t = '\0'; + } + else + break; + } + g_free (complete); + } + else + { + translation = dgettext (domain, menupath); + } /* * Work around a bug in GTK+ prior to 1.2.7 (similar workaround below) */ - if (strncmp (factory, translation, strlen (factory)) == 0) - retval = translation + strlen (factory); + if (strncmp (factory, translation, strlen (factory)) == 0) + { + retval = translation + strlen (factory); + if (complete) + { + /* assign the result to menu_path, so it gets freed on next call */ + g_free (menupath); + menupath = translation; + } + } else - g_warning ("bad translation for menupath: %s", menupath); + { + g_warning ("bad translation for menupath: %s", menupath); + if (complete) + g_free (translation); + } } else { diff --git a/plug-ins/gap/gap_frontends_main.c b/plug-ins/gap/gap_frontends_main.c index 913061eb50..dec14677ce 100644 --- a/plug-ins/gap/gap_frontends_main.c +++ b/plug-ins/gap/gap_frontends_main.c @@ -75,14 +75,6 @@ static char *gap_main_version = "1.1.11b; 1999/11/20"; int gap_debug = 0; -/* for i18n */ - -static gchar G_GNUC_UNUSED *dummy_entries[] = -{ - N_("/Video"), - N_("/Video/Encode") -}; - static void query(void); static void run(char *name, int nparam, GParam *param, int *nretvals, GParam **retvals); diff --git a/plug-ins/perl/po/de.po b/plug-ins/perl/po/de.po index f5e602fc32..2d42a8b335 100644 --- a/plug-ins/perl/po/de.po +++ b/plug-ins/perl/po/de.po @@ -663,7 +663,7 @@ msgid "TYPE" msgstr "TYP" msgid "/Guides/To Selection" -msgstr "/Guides/Als Auswahl" +msgstr "/Hilfslinien/Als Auswahl" msgid "/Filters/Noise/Feedback" msgstr "/Filter/Noise/Feedback" @@ -758,7 +758,7 @@ msgid "only blessed scalars accepted here" msgstr "Objekt (nicht Referenz oder Skalar) benötigt" msgid "/Guides/Center Guide" -msgstr "" +msgstr "/Hilfslinien/Zentriert" msgid "illegal parasite specification, arrayref expected" msgstr "Illegaler Typ für 'parasite', erwarte Referenz auf Array" diff --git a/plug-ins/script-fu/script-fu.c b/plug-ins/script-fu/script-fu.c index 98eaf68260..9e47a78a09 100644 --- a/plug-ins/script-fu/script-fu.c +++ b/plug-ins/script-fu/script-fu.c @@ -121,26 +121,6 @@ sfquit (void) static void query (void) { - static gchar G_GNUC_UNUSED *dummy_entries[] = { - N_("/Xtns/Script-Fu"), - N_("/Xtns/Script-Fu/Logos"), - N_("/Xtns/Script-Fu/Patterns"), - N_("/Xtns/Script-Fu/Web Page Themes"), - N_("/Xtns/Script-Fu/Utils"), - N_("/Xtns/Script-Fu/Buttons"), - N_("/Xtns/Script-Fu/Make Brush"), - N_("/Xtns/Script-Fu/Misc"), - N_("/Xtns/Script-Fu/Test"), - N_("/Script-Fu/Decor"), - N_("/Script-Fu/Utils"), - N_("/Script-Fu/Animators"), - N_("/Script-Fu/Stencil Ops"), - N_("/Script-Fu/Alchemy"), - N_("/Script-Fu/Selection"), - N_("/Script-Fu/Shadow"), - N_("/Script-Fu/Render"), - }; - static GParamDef console_args[] = { { PARAM_INT32, "run_mode", "Interactive, [non-interactive]" } diff --git a/plug-ins/webbrowser/webbrowser.c b/plug-ins/webbrowser/webbrowser.c index 08b7646ea0..f2c3e9712b 100644 --- a/plug-ins/webbrowser/webbrowser.c +++ b/plug-ins/webbrowser/webbrowser.c @@ -112,7 +112,6 @@ query () static int nargs = sizeof (args) / sizeof (args[0]); static GParamDef *return_vals = NULL; static int nreturn_vals = 0; - static gchar G_GNUC_UNUSED *dummy_entries = N_("/Xtns/Web Browser"); INIT_I18N();