summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <matthiasc@src.gnome.org>2008-12-08 03:57:16 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2008-12-08 03:57:16 +0000
commit70675377c00c2f164feb6ec78912812bfa0aad40 (patch)
tree9f0331308d3426d0715ba46e4ed7ae800c4e3c94
parent2afd463b2628e3c3e6184a17bccb60706d48ff87 (diff)
downloadgtk+-70675377c00c2f164feb6ec78912812bfa0aad40.tar.gz
Make gtk_builder_get_translation_domain() useful for subparsers.
* gtk/gtkbuilderparser.c: Make gtk_builder_get_translation_domain() useful for subparsers. * gtk/gtkcontainer.c: Make the child property parser support translatable child properties. svn path=/trunk/; revision=21855
-rw-r--r--ChangeLog10
-rw-r--r--docs/reference/ChangeLog5
-rw-r--r--docs/reference/gtk/tmpl/gtkcontainer.sgml5
-rw-r--r--gtk/gtkbuilderparser.c34
-rw-r--r--gtk/gtkcontainer.c38
5 files changed, 86 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 97e74dca26..b66500926f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2008-12-07 Matthias Clasen <mclasen@redhat.com>
+ * gtk/gtkbuilderparser.c: Make gtk_builder_get_translation_domain()
+ useful for subparsers.
+
+ * gtk/gtkcontainer.c: Make the child property parser support
+ translatable child properties.
+
+2008-12-07 Matthias Clasen <mclasen@redhat.com>
+
Bug 554274 – Add default hook for GtkLinkButton
* gtk/gtklinkbutton.c: Call gtk_show_uri() if no uri hook has
@@ -8,7 +16,7 @@
2008-12-07 Matthias Clasen <mclasen@redhat.com>
Bug 559325 – documentation for gdk_display_get_window_at_pointer()
- is wrong
+: is wrong
* gdk/gdkdisplay.c (gdk_display_get_window_at_pointer): Correct
the documentation. Patch by Paul Davis
diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog
index b302b6a00c..0fa917f43a 100644
--- a/docs/reference/ChangeLog
+++ b/docs/reference/ChangeLog
@@ -1,3 +1,8 @@
+2008-12-07 Matthias Clasen <mclasen@redhat.com>
+
+ * gtk/tmpl/gtkcontainer.sgml: Document translatable child
+ properties in GtkBuilder
+
2008-11-29 Baptiste Mille-Mathias <baptiste.millemathias@gmail.com>
* docs/reference/gtk/images/accel-label.png:
diff --git a/docs/reference/gtk/tmpl/gtkcontainer.sgml b/docs/reference/gtk/tmpl/gtkcontainer.sgml
index 01c819e77d..7d28b5bc35 100644
--- a/docs/reference/gtk/tmpl/gtkcontainer.sgml
+++ b/docs/reference/gtk/tmpl/gtkcontainer.sgml
@@ -125,6 +125,11 @@ child properties for the child.
</object>
]]></programlisting>
</example>
+<para>
+Since 2.16, child properties can also be marked as translatable using
+the same "translatable", "comments" and "context" attributes that are used
+for regular properties.
+</para>
</refsect2>
<!-- ##### SECTION See_Also ##### -->
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c
index d1057811a3..f4cb947a80 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -634,9 +634,24 @@ parse_interface (ParserData *data,
{
if (strcmp (names[i], "domain") == 0)
{
- g_free (data->domain);
- data->domain = g_strdup (values[i]);
- break;
+
+ if (data->domain)
+ {
+ if (strcmp (data->domain, values[i]) == 0)
+ continue;
+ else
+ g_warning ("%s: interface domain '%s' overrides "
+ "programically set domain '%s'",
+ data->filename,
+ values[i],
+ data->domain
+ );
+
+ g_free (data->domain);
+ }
+
+ data->domain = g_strdup (values[i]);
+ gtk_builder_set_translation_domain (data->builder, data->domain);
}
else
error_invalid_attribute (data, "interface", names[i], error);
@@ -1116,13 +1131,21 @@ _gtk_builder_parser_parse_buffer (GtkBuilder *builder,
gchar **requested_objs,
GError **error)
{
+ const gchar* domain;
ParserData *data;
GSList *l;
+ /* Store the original domain so that interface domain attribute can be
+ * applied for the builder and the original domain can be restored after
+ * parsing has finished. This allows subparsers to translate elements with
+ * gtk_builder_get_translation_domain() without breaking the ABI or API
+ */
+ domain = gtk_builder_get_translation_domain (builder);
+
data = g_new0 (ParserData, 1);
data->builder = builder;
data->filename = filename;
- data->domain = g_strdup (gtk_builder_get_translation_domain (builder));
+ data->domain = g_strdup (domain);
data->requested_objects = NULL;
if (requested_objs)
@@ -1184,4 +1207,7 @@ _gtk_builder_parser_parse_buffer (GtkBuilder *builder,
g_free (data->domain);
g_markup_parse_context_free (data->ctx);
g_free (data);
+
+ /* restore the original domain */
+ gtk_builder_set_translation_domain (builder, domain);
}
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 516773af01..0ee531828e 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -31,6 +31,7 @@
#include "gtkcontainer.h"
#include "gtkbuildable.h"
+#include "gtkbuilderprivate.h"
#include "gtkprivate.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
@@ -361,6 +362,8 @@ typedef struct {
GtkContainer *container;
GtkWidget *child;
gchar *child_prop_name;
+ gchar *context;
+ gboolean translatable
} PackingPropertiesData;
static void
@@ -379,6 +382,20 @@ attributes_start_element (GMarkupParseContext *context,
for (i = 0; names[i]; i++)
if (strcmp (names[i], "name") == 0)
parser_data->child_prop_name = g_strdup (values[i]);
+ else if (strcmp (names[i], "translatable") == 0)
+ {
+ if (!_gtk_builder_boolean_from_string (values[1],
+ &parser_data->translatable,
+ error))
+ return;
+ }
+ else if (strcmp (names[i], "comments") == 0)
+ ; /* for translators */
+ else if (strcmp (names[i], "context") == 0)
+ parser_data->context = g_strdup (values[1]);
+ else
+ g_warning ("Unsupported attribute for GtkContainer Child "
+ "property: %s\n", names[i]);
}
else if (strcmp (element_name, "packing") == 0)
return;
@@ -394,18 +411,37 @@ attributes_text_element (GMarkupParseContext *context,
GError **error)
{
PackingPropertiesData *parser_data = (PackingPropertiesData*)user_data;
+ const gchar* value;
if (!parser_data->child_prop_name)
return;
+
+ if (parser_data->translatable && text_len)
+ {
+ const gchar* domain;
+ domain = gtk_builder_get_translation_domain (parser_data->builder);
+
+ value = _gtk_builder_parser_translate (domain,
+ parser_data->context,
+ text);
+ }
+ else
+ {
+ value = g_strdup (text);
+ }
gtk_container_buildable_set_child_property (parser_data->container,
parser_data->builder,
parser_data->child,
parser_data->child_prop_name,
- text);
+ value);
g_free (parser_data->child_prop_name);
+ g_free (parser_data->context);
+ g_free (value);
parser_data->child_prop_name = NULL;
+ parser_data->context = NULL;
+ parser_data->translatable = FALSE;
}
static const GMarkupParser attributes_parser =