Commit 70675377 authored by Matthias Clasen's avatar Matthias Clasen

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
parent 2afd463b
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
......@@ -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
......
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:
......
......@@ -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 ##### -->
......
......@@ -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);
}
......@@ -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 =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment