]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Extract msgctxt from Glade input files.
authorDaiki Ueno <ueno@gnu.org>
Wed, 30 Jan 2013 07:21:50 +0000 (16:21 +0900)
committerDaiki Ueno <ueno@gnu.org>
Fri, 15 Mar 2013 02:57:39 +0000 (11:57 +0900)
gettext-tools/src/ChangeLog
gettext-tools/src/x-glade.c

index c1d8ad44a4e0bff563f24b38607e98813df1467f..66bd3c4c4bd0452b33a3a8f41c71b9c34528c07e 100644 (file)
@@ -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
index 11f839706dc1869280ecc4c5418f7623e92f3219..85ed21c3c0c75c5ff1b6eb27115fab6576fa30ec 100644 (file)
@@ -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);
         }
     }