From 262dc2d7d375acec2c091fad699a766ffe6161f9 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 6 May 2004 04:25:45 +0000 Subject: [PATCH] New function to translate a string with translate_func. (#135740) Thu May 6 00:24:11 2004 Matthias Clasen * gtk/gtkactiongroup.h: * gtk/gtkactiongroup.c (gtk_action_group_translate_string): New function to translate a string with translate_func. (#135740) --- ChangeLog | 7 +++ ChangeLog.pre-2-10 | 7 +++ ChangeLog.pre-2-6 | 7 +++ ChangeLog.pre-2-8 | 7 +++ docs/reference/ChangeLog | 4 ++ docs/reference/gtk/gtk-sections.txt | 1 + gtk/gtkactiongroup.c | 81 +++++++++++++---------------- gtk/gtkactiongroup.h | 2 + 8 files changed, 71 insertions(+), 45 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15ea51f1b8..577a3bba4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu May 6 00:24:11 2004 Matthias Clasen + + * gtk/gtkactiongroup.h: + * gtk/gtkactiongroup.c (gtk_action_group_translate_string): + New function to translate a string with translate_func. + (#135740) + Thu May 6 00:02:21 2004 Matthias Clasen * gtk/gtkcombobox.c (gtk_combo_box_get_wrap_width): diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 15ea51f1b8..577a3bba4c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Thu May 6 00:24:11 2004 Matthias Clasen + + * gtk/gtkactiongroup.h: + * gtk/gtkactiongroup.c (gtk_action_group_translate_string): + New function to translate a string with translate_func. + (#135740) + Thu May 6 00:02:21 2004 Matthias Clasen * gtk/gtkcombobox.c (gtk_combo_box_get_wrap_width): diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 15ea51f1b8..577a3bba4c 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Thu May 6 00:24:11 2004 Matthias Clasen + + * gtk/gtkactiongroup.h: + * gtk/gtkactiongroup.c (gtk_action_group_translate_string): + New function to translate a string with translate_func. + (#135740) + Thu May 6 00:02:21 2004 Matthias Clasen * gtk/gtkcombobox.c (gtk_combo_box_get_wrap_width): diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 15ea51f1b8..577a3bba4c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Thu May 6 00:24:11 2004 Matthias Clasen + + * gtk/gtkactiongroup.h: + * gtk/gtkactiongroup.c (gtk_action_group_translate_string): + New function to translate a string with translate_func. + (#135740) + Thu May 6 00:02:21 2004 Matthias Clasen * gtk/gtkcombobox.c (gtk_combo_box_get_wrap_width): diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index abfc3d5629..444d5a6895 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +Thu May 6 00:22:38 2004 Matthias Clasen + + * gtk/gtk-sections.txt: Add gtk_action_group_translate_string() + Thu May 6 00:04:03 2004 Matthias Clasen * gtk/gtk-sections.txt: Add missing getters. diff --git a/docs/reference/gtk/gtk-sections.txt b/docs/reference/gtk/gtk-sections.txt index 1c02125f36..f9c975a0bf 100644 --- a/docs/reference/gtk/gtk-sections.txt +++ b/docs/reference/gtk/gtk-sections.txt @@ -175,6 +175,7 @@ gtk_action_group_add_radio_actions gtk_action_group_add_radio_actions_full gtk_action_group_set_translate_func gtk_action_group_set_translation_domain +gtk_action_group_translate_string GTK_TYPE_ACTION_GROUP GTK_ACTION_GROUP diff --git a/gtk/gtkactiongroup.c b/gtk/gtkactiongroup.c index f265bd2c29..1072db14b4 100644 --- a/gtk/gtkactiongroup.c +++ b/gtk/gtkactiongroup.c @@ -738,15 +738,10 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group, * gtk_action_group_add_..._actions_full() functions. */ guint i; - GtkTranslateFunc translate_func; - gpointer translate_data; SharedData *shared_data; g_return_if_fail (GTK_IS_ACTION_GROUP (action_group)); - translate_func = action_group->private_data->translate_func; - translate_data = action_group->private_data->translate_data; - shared_data = g_new0 (SharedData, 1); shared_data->ref_count = 1; shared_data->data = user_data; @@ -758,16 +753,8 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group, const gchar *label; const gchar *tooltip; - if (translate_func) - { - label = translate_func (entries[i].label, translate_data); - tooltip = translate_func (entries[i].tooltip, translate_data); - } - else - { - label = entries[i].label; - tooltip = entries[i].tooltip; - } + label = gtk_action_group_translate_string (action_group, entries[i].label); + tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip); action = gtk_action_new (entries[i].name, label, @@ -847,15 +834,10 @@ gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group, * gtk_action_group_add_..._actions_full() functions. */ guint i; - GtkTranslateFunc translate_func; - gpointer translate_data; SharedData *shared_data; g_return_if_fail (GTK_IS_ACTION_GROUP (action_group)); - translate_func = action_group->private_data->translate_func; - translate_data = action_group->private_data->translate_data; - shared_data = g_new0 (SharedData, 1); shared_data->ref_count = 1; shared_data->data = user_data; @@ -867,16 +849,8 @@ gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group, const gchar *label; const gchar *tooltip; - if (translate_func) - { - label = translate_func (entries[i].label, translate_data); - tooltip = translate_func (entries[i].tooltip, translate_data); - } - else - { - label = entries[i].label; - tooltip = entries[i].tooltip; - } + label = gtk_action_group_translate_string (action_group, entries[i].label); + tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip); action = gtk_toggle_action_new (entries[i].name, label, @@ -968,32 +942,19 @@ gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group, * gtk_action_group_add_..._actions_full() functions. */ guint i; - GtkTranslateFunc translate_func; - gpointer translate_data; GSList *group = NULL; GtkRadioAction *first_action = NULL; g_return_if_fail (GTK_IS_ACTION_GROUP (action_group)); - translate_func = action_group->private_data->translate_func; - translate_data = action_group->private_data->translate_data; - for (i = 0; i < n_entries; i++) { GtkRadioAction *action; const gchar *label; const gchar *tooltip; - if (translate_func) - { - label = translate_func (entries[i].label, translate_data); - tooltip = translate_func (entries[i].tooltip, translate_data); - } - else - { - label = entries[i].label; - tooltip = entries[i].tooltip; - } + label = gtk_action_group_translate_string (action_group, entries[i].label); + tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip); action = gtk_radio_action_new (entries[i].name, label, @@ -1087,6 +1048,36 @@ gtk_action_group_set_translation_domain (GtkActionGroup *action_group, g_free); } +/** + * gtk_action_group_translate_string: + * @action_group: a #GtkActionGroup + * @string: a string + * + * Translates a string using the specified translate_func(). This + * is mainly intended for language bindings. + * + * Returns: the translation of @string + * + * Since: 2.6 + **/ +gchar * +gtk_action_group_translate_string (GtkActionGroup *action_group, + const gchar *string) +{ + GtkTranslateFunc translate_func; + gpointer translate_data; + + g_return_if_fail (GTK_IS_ACTION_GROUP (action_group)); + + translate_func = action_group->private_data->translate_func; + translate_data = action_group->private_data->translate_data; + + if (translate_func) + return translate_func (string, translate_data); + else + return string; +} + /* Protected for use by GtkAction */ void _gtk_action_group_emit_connect_proxy (GtkActionGroup *action_group, diff --git a/gtk/gtkactiongroup.h b/gtk/gtkactiongroup.h index 5d91dccf07..26c50410e6 100644 --- a/gtk/gtkactiongroup.h +++ b/gtk/gtkactiongroup.h @@ -160,6 +160,8 @@ void gtk_action_group_set_translate_func (GtkActionGroup * GtkDestroyNotify notify); void gtk_action_group_set_translation_domain (GtkActionGroup *action_group, const gchar *domain); +gchar *gtk_action_group_translate_string (GtkActionGroup *action_group, + const gchar *string); /* Protected for use by GtkAction */ void _gtk_action_group_emit_connect_proxy (GtkActionGroup *action_group,