diff options
author | Matthias Clasen <matthiasc@src.gnome.org> | 2007-07-08 05:27:22 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2007-07-08 05:27:22 +0000 |
commit | 5f3729b87c8ebd6b6aac1d0eee2ae136e0bf34dd (patch) | |
tree | d0f0463c1ce2e55daad425675a98814fa153ef8b /gtk/gtkbuilderparser.c | |
parent | 6942fa3981e8c09465a808f28e0f162d1e8d1cfc (diff) | |
download | gtk+-5f3729b87c8ebd6b6aac1d0eee2ae136e0bf34dd.tar.gz |
Add support for context and comments on properties
svn path=/trunk/; revision=18401
Diffstat (limited to 'gtk/gtkbuilderparser.c')
-rw-r--r-- | gtk/gtkbuilderparser.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c index 2996ac8a4f..d7605fea1e 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); } |