diff options
author | Daiki Ueno <ueno@gnu.org> | 2013-01-30 16:21:50 +0900 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2013-03-15 11:57:39 +0900 |
commit | 852df7d303d83fa2b89675f2d08478eb75ce454d (patch) | |
tree | 3f1076f054c286abd489c2983713dd8215f4cca1 /gettext-tools | |
parent | 0a6cca9ae8fa14ebebde309cf54cedc522b01df9 (diff) | |
download | external_gettext-852df7d303d83fa2b89675f2d08478eb75ce454d.zip external_gettext-852df7d303d83fa2b89675f2d08478eb75ce454d.tar.gz external_gettext-852df7d303d83fa2b89675f2d08478eb75ce454d.tar.bz2 |
Extract msgctxt from Glade input files.
Diffstat (limited to 'gettext-tools')
-rw-r--r-- | gettext-tools/src/ChangeLog | 10 | ||||
-rw-r--r-- | gettext-tools/src/x-glade.c | 43 |
2 files changed, 50 insertions, 3 deletions
diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index c1d8ad4..66bd3c4 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,13 @@ +2013-03-15 Miguel Ángel Arruga Vivas <rosen644835@gmail.com> + Daiki Ueno <ueno@gnu.org> + + Extract msgctxt from Glade input files. + Reported at <https://savannah.gnu.org/bugs/?34506> + * x-glade.c (struct element_state): Add field 'extract_context'. + (start_element_handler): Check "context" attribute if the string + contains msgctxt. + (end_element_handler): Extract msgctxt if extract_context is set. + 2013-02-25 Daiki Ueno <ueno@gnu.org> * Makefile.am (libgettextsrc_la_CPPFLAGS): Define to specify Woe32 diff --git a/gettext-tools/src/x-glade.c b/gettext-tools/src/x-glade.c index 11f8397..85ed21c 100644 --- a/gettext-tools/src/x-glade.c +++ b/gettext-tools/src/x-glade.c @@ -385,6 +385,7 @@ static XML_Parser parser; struct element_state { bool extract_string; + bool extract_context; char *extracted_comment; int lineno; char *buffer; @@ -428,6 +429,7 @@ start_element_handler (void *userData, const char *name, p = &stack[stack_depth]; p->extract_string = extract_all; + p->extract_context = false; p->extracted_comment = NULL; /* In Glade 1, a few specific elements are translatable. */ if (!p->extract_string) @@ -443,6 +445,7 @@ start_element_handler (void *userData, const char *name, && (strcmp (name, "property") == 0 || strcmp (name, "atkproperty") == 0)) { bool has_translatable = false; + bool has_context = false; const char *extracted_comment = NULL; const char **attp = attributes; while (*attp != NULL) @@ -451,9 +454,12 @@ start_element_handler (void *userData, const char *name, has_translatable = (strcmp (attp[1], "yes") == 0); else if (strcmp (attp[0], "comments") == 0) extracted_comment = attp[1]; + else if (strcmp (attp[0], "context") == 0) + has_context = (strcmp (attp[1], "yes") == 0); attp += 2; } p->extract_string = has_translatable; + p->extract_context = has_context; p->extracted_comment = (has_translatable && extracted_comment != NULL ? xstrdup (extracted_comment) @@ -504,6 +510,8 @@ end_element_handler (void *userData, const char *name) if (p->buflen > 0) { lex_pos_ty pos; + char *msgid = NULL; + char *msgctxt = NULL; if (p->buflen == p->bufmax) p->buffer = (char *) xrealloc (p->buffer, p->buflen + 1); @@ -512,9 +520,38 @@ end_element_handler (void *userData, const char *name) pos.file_name = logical_file_name; pos.line_number = p->lineno; - remember_a_message (mlp, NULL, p->buffer, null_context, &pos, - p->extracted_comment, savable_comment); - p->buffer = NULL; + if (p->extract_context) + { + char *separator = strchr (p->buffer, '|'); + + if (separator == NULL) + { + error_with_progname = false; + error_at_line (0, 0, + pos.file_name, + pos.line_number, + _("\ +Missing context for the string extracted from '%s' element"), + name); + error_with_progname = true; + } + else + { + *separator = '\0'; + msgid = xstrdup (separator + 1); + msgctxt = xstrdup (p->buffer); + } + } + else + { + msgid = p->buffer; + p->buffer = NULL; + } + + if (msgid != NULL) + remember_a_message (mlp, msgctxt, msgid, + null_context, &pos, + p->extracted_comment, savable_comment); } } |