[gnome-builder] egg-radio-box: implement translation support
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] egg-radio-box: implement translation support
- Date: Tue, 11 Oct 2016 22:25:35 +0000 (UTC)
commit 932097e9b2cadef32318cf04049d43c9bd5bbfa2
Author: Christian Hergert <chergert redhat com>
Date: Tue Oct 11 15:04:47 2016 -0700
egg-radio-box: implement translation support
We were missing translation support when reading data in from
GtkBuilder UI definitions. This uses the translation domain
of the GtkBuilder file to get the translation for the input
text if translatable="yes" in the property definition.
https://bugzilla.gnome.org/show_bug.cgi?id=772733
contrib/egg/egg-radio-box.c | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
---
diff --git a/contrib/egg/egg-radio-box.c b/contrib/egg/egg-radio-box.c
index 297e9e4..90fe7ae 100644
--- a/contrib/egg/egg-radio-box.c
+++ b/contrib/egg/egg-radio-box.c
@@ -348,8 +348,10 @@ egg_radio_box_new (void)
typedef struct
{
EggRadioBox *self;
+ GtkBuilder *builder;
gchar *id;
GString *text;
+ guint translatable : 1;
} ItemParserData;
static void
@@ -378,6 +380,8 @@ item_parser_start_element (GMarkupParseContext *context,
G_MARKUP_COLLECT_STRING, "translatable", &translatable,
G_MARKUP_COLLECT_INVALID))
return;
+
+ parser_data->translatable = translatable != NULL && g_str_equal ("yes", translatable);
}
}
@@ -396,7 +400,19 @@ item_parser_end_element (GMarkupParseContext *context,
if (g_strcmp0 (element_name, "item") == 0)
{
if (parser_data->id && parser_data->text != NULL)
- egg_radio_box_add_item (parser_data->self, parser_data->id, parser_data->text->str);
+ {
+ const gchar *str = parser_data->text->str;
+
+ if (parser_data->translatable && str != NULL)
+ {
+ const gchar *domain;
+
+ domain = gtk_builder_get_translation_domain (parser_data->builder);
+ str = g_dgettext (domain, str);
+ }
+
+ egg_radio_box_add_item (parser_data->self, parser_data->id, str);
+ }
}
}
@@ -445,6 +461,7 @@ egg_radio_box_custom_tag_start (GtkBuildable *buildable,
parser_data = g_slice_new0 (ItemParserData);
parser_data->self = self;
+ parser_data->builder = builder;
*parser = ItemParser;
*data = parser_data;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]