Add support for context and comments on properties
svn path=/trunk/; revision=18401
This commit is contained in:
@ -1,3 +1,9 @@
|
|||||||
|
2007-07-07 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* gtk/gtkbuilderprivate.h:
|
||||||
|
* gtk/gtkbuilderparser.c: Support context and comments
|
||||||
|
for properties.
|
||||||
|
|
||||||
2007-07-07 Matthias Clasen <mclasen@redhat.com>
|
2007-07-07 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* gtk/gtkwidget.c: Fix some typos, and a memory management bug.
|
* gtk/gtkwidget.c: Fix some typos, and a memory management bug.
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
2007-07-07 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* gtk/tmpl/gtkbuilder.sgml: Document context and
|
||||||
|
comments for properties.
|
||||||
|
|
||||||
2007-07-07 Johan Dahlin <jdahlin@async.com.br>
|
2007-07-07 Johan Dahlin <jdahlin@async.com.br>
|
||||||
|
|
||||||
* gtk/gtk-builder-convert.xml: Update
|
* gtk/gtk-builder-convert.xml: Update
|
||||||
|
@ -62,7 +62,9 @@ which are more limited in scope.
|
|||||||
type-func #IMPLIED
|
type-func #IMPLIED
|
||||||
constructor #IMPLIED >
|
constructor #IMPLIED >
|
||||||
<!ATTLIST property name #REQUIRED
|
<!ATTLIST property name #REQUIRED
|
||||||
translatable #IMPLIED >
|
translatable #IMPLIED
|
||||||
|
comments #IMPLIED
|
||||||
|
context #IMPLIED >
|
||||||
<!ATTLIST signal name #REQUIRED
|
<!ATTLIST signal name #REQUIRED
|
||||||
handler #REQUIRED
|
handler #REQUIRED
|
||||||
after #IMPLIED
|
after #IMPLIED
|
||||||
@ -114,7 +116,9 @@ set to a true value, GTK+ uses gettext() (or dgettext() if
|
|||||||
the builder has a translation domain set) to find a translation
|
the builder has a translation domain set) to find a translation
|
||||||
for the value. This happens before the value is parsed, so
|
for the value. This happens before the value is parsed, so
|
||||||
it can be used for properties of any type, but it is probably
|
it can be used for properties of any type, but it is probably
|
||||||
most useful for string properties.
|
most useful for string properties. It is also possible to
|
||||||
|
specify a context to disambiguate short strings, and comments
|
||||||
|
which may help the translators.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
GtkBuilder can parse textual representations for the most
|
GtkBuilder can parse textual representations for the most
|
||||||
|
@ -393,6 +393,7 @@ parse_property (ParserData *data,
|
|||||||
{
|
{
|
||||||
PropertyInfo *info;
|
PropertyInfo *info;
|
||||||
gchar *name = NULL;
|
gchar *name = NULL;
|
||||||
|
gchar *context = NULL;
|
||||||
gboolean translatable = FALSE;
|
gboolean translatable = FALSE;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -408,6 +409,14 @@ parse_property (ParserData *data,
|
|||||||
error))
|
error))
|
||||||
return;
|
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
|
else
|
||||||
{
|
{
|
||||||
error_invalid_attribute (data, element_name, names[i], error);
|
error_invalid_attribute (data, element_name, names[i], error);
|
||||||
@ -424,6 +433,7 @@ parse_property (ParserData *data,
|
|||||||
info = g_slice_new0 (PropertyInfo);
|
info = g_slice_new0 (PropertyInfo);
|
||||||
info->name = name;
|
info->name = name;
|
||||||
info->translatable = translatable;
|
info->translatable = translatable;
|
||||||
|
info->context = context;
|
||||||
state_push (data, info);
|
state_push (data, info);
|
||||||
|
|
||||||
info->tag.name = element_name;
|
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 */
|
/* Called for character data */
|
||||||
/* text is not nul-terminated */
|
/* text is not nul-terminated */
|
||||||
static void
|
static void
|
||||||
@ -865,10 +900,10 @@ text (GMarkupParseContext *context,
|
|||||||
|
|
||||||
if (prop_info->translatable && text_len)
|
if (prop_info->translatable && text_len)
|
||||||
{
|
{
|
||||||
if (data->domain)
|
if (prop_info->context)
|
||||||
text = dgettext (data->domain, text);
|
text = dpgettext (data->domain, prop_info->context, text);
|
||||||
else
|
else
|
||||||
text = gettext (text);
|
text = dgettext (data->domain, text);
|
||||||
}
|
}
|
||||||
prop_info->data = g_strndup (text, text_len);
|
prop_info->data = g_strndup (text, text_len);
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,7 @@ typedef struct {
|
|||||||
gchar *name;
|
gchar *name;
|
||||||
gchar *data;
|
gchar *data;
|
||||||
gboolean translatable;
|
gboolean translatable;
|
||||||
|
gchar *context;
|
||||||
} PropertyInfo;
|
} PropertyInfo;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Reference in New Issue
Block a user