From 5f3729b87c8ebd6b6aac1d0eee2ae136e0bf34dd Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 8 Jul 2007 05:27:22 +0000 Subject: Add support for context and comments on properties svn path=/trunk/; revision=18401 --- ChangeLog | 6 +++++ docs/reference/ChangeLog | 5 ++++ docs/reference/gtk/tmpl/gtkbuilder.sgml | 8 +++++-- gtk/gtkbuilderparser.c | 41 ++++++++++++++++++++++++++++++--- gtk/gtkbuilderprivate.h | 1 + 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index de7971429..2d2250744 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-07-07 Matthias Clasen + + * gtk/gtkbuilderprivate.h: + * gtk/gtkbuilderparser.c: Support context and comments + for properties. + 2007-07-07 Matthias Clasen * gtk/gtkwidget.c: Fix some typos, and a memory management bug. diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 3a649df29..7325eda06 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,8 @@ +2007-07-07 Matthias Clasen + + * gtk/tmpl/gtkbuilder.sgml: Document context and + comments for properties. + 2007-07-07 Johan Dahlin * gtk/gtk-builder-convert.xml: Update diff --git a/docs/reference/gtk/tmpl/gtkbuilder.sgml b/docs/reference/gtk/tmpl/gtkbuilder.sgml index f9a45d74d..1a83eb3cb 100644 --- a/docs/reference/gtk/tmpl/gtkbuilder.sgml +++ b/docs/reference/gtk/tmpl/gtkbuilder.sgml @@ -62,7 +62,9 @@ which are more limited in scope. type-func #IMPLIED constructor #IMPLIED > + translatable #IMPLIED + comments #IMPLIED + context #IMPLIED > GtkBuilder can parse textual representations for the most diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c index 2996ac8a4..d7605fea1 100644 --- a/gtk/gtkbuilderparser.c +++ b/gtk/gtkbuilderparser.c @@ -393,6 +393,7 @@ parse_property (ParserData *data, { PropertyInfo *info; gchar *name = NULL; + gchar *context = NULL; gboolean translatable = FALSE; int i; @@ -408,6 +409,14 @@ parse_property (ParserData *data, error)) return; } + else if (strcmp (names[i], "comments") == 0) + { + /* do nothing, comments are for translators */ + } + else if (strcmp (names[i], "context") == 0) + { + context = g_strdup (values[i]); + } else { error_invalid_attribute (data, element_name, names[i], error); @@ -424,6 +433,7 @@ parse_property (ParserData *data, info = g_slice_new0 (PropertyInfo); info->name = name; info->translatable = translatable; + info->context = context; state_push (data, info); info->tag.name = element_name; @@ -833,6 +843,31 @@ end_element (GMarkupParseContext *context, } } +/* This function is taken from gettext.h + * GNU gettext uses '\004' to separate context and msgid in .mo files. + */ +static const char * +dpgettext (const char *domain, + const char *msgctxt, + const char *msgid) +{ + size_t msgctxt_len = strlen (msgctxt) + 1; + size_t msgid_len = strlen (msgid) + 1; + const char *translation; + char msg_ctxt_id[msgctxt_len + msgid_len]; + + memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1); + msg_ctxt_id[msgctxt_len - 1] = '\004'; + memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len); + + translation = dgettext (domain, msg_ctxt_id); + + if (translation != msg_ctxt_id) + return translation; + + return msgid; +} + /* Called for character data */ /* text is not nul-terminated */ static void @@ -865,10 +900,10 @@ text (GMarkupParseContext *context, if (prop_info->translatable && text_len) { - if (data->domain) - text = dgettext (data->domain, text); + if (prop_info->context) + text = dpgettext (data->domain, prop_info->context, text); else - text = gettext (text); + text = dgettext (data->domain, text); } prop_info->data = g_strndup (text, text_len); } diff --git a/gtk/gtkbuilderprivate.h b/gtk/gtkbuilderprivate.h index 70c9f7941..1c3f18e68 100644 --- a/gtk/gtkbuilderprivate.h +++ b/gtk/gtkbuilderprivate.h @@ -61,6 +61,7 @@ typedef struct { gchar *name; gchar *data; gboolean translatable; + gchar *context; } PropertyInfo; typedef struct { -- cgit v1.2.1