Gabor Kelemen <[email protected]> wrote: 
> Hi
Hi Gabor,

> I have been playing with gettext 0.18.3 and Gnome stuff, when I noticed
> the following extraction error:
> 
> $ xgettext -o unixpr.pot gtk/gtkprintunixdialog.ui
> $ msgfmt -c unixpr.pot
> unixpr.pot:254: keyword "It" unknown
> unixpr.pot:254:3: syntax error
> msgfmt: unixpr.pot: warning: PO file header fuzzy
>                     warning: older versions of msgfmt will give an error
> on this
> msgfmt: found 2 fatal errors

Thank you for the bug report. The attached patch solves that problem,
but also fixes --add-comment=COMMENT flag for Glade extractor. This
option is now mandatory for comment extraction. Any comment (about the
patch, I mean) is welcome. :)

Happy Hacking!
Miguel
>From f911aa9d9209a6a78d4eafaf68574189418bfe0a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?= <[email protected]>
Date: Sun, 11 Aug 2013 16:53:49 +0200
Subject: [PATCH] x-glade: Fix comment extraction.

---
 gettext-tools/src/ChangeLog |   11 +++++++++++
 gettext-tools/src/x-glade.c |   28 ++++++++--------------------
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog
index 38dc376..4060a37 100644
--- a/gettext-tools/src/ChangeLog
+++ b/gettext-tools/src/ChangeLog
@@ -1,3 +1,14 @@
+2013-08-11  Miguel Angel Arruga Vivas  <[email protected]>
+
+	* x-glade.c (struct element_state): Remove field extracted_comment.
+	(comment_handler): Add foward declaration.
+	(start_element_glade2): Call comment_handler.
+	(start_element_gtkbuilder): Likewise.
+	(end_element_glade2): Remove extracted_comment references.
+	(end_element_gtkbuilder): Likewise.
+	(start_element_handler): Likewise.
+	(end_element_handler): Likewise.
+
 2013-08-09  Daiki Ueno  <[email protected]>
 
 	* x-gsettings.c (extract_gsettings): Add guard when expat is not
diff --git a/gettext-tools/src/x-glade.c b/gettext-tools/src/x-glade.c
index d95cd8e..7a6124e 100644
--- a/gettext-tools/src/x-glade.c
+++ b/gettext-tools/src/x-glade.c
@@ -132,7 +132,6 @@ struct element_state
 {
   bool extract_string;
   bool extract_context;         /* used by Glade 2 */
-  char *extracted_comment;      /* used by Glade 2 or GtkBuilder */
   char *extracted_context;      /* used by GtkBuilder */
   int lineno;
   char *buffer;
@@ -203,11 +202,14 @@ end_element_glade1 (struct element_state *p, const char *name)
     {
       remember_a_message (mlp, NULL, p->buffer,
                           null_context, &pos,
-                          p->extracted_comment, savable_comment);
+                          NULL, savable_comment);
       p->buffer = NULL;
     }
 }
 
+/* Foward declaration of needed local function.  */
+static void comment_handler (void *userData, const char *data);
+
 static void
 start_element_glade2 (struct element_state *p, const char *name,
                       const char **attributes)
@@ -224,24 +226,19 @@ start_element_glade2 (struct element_state *p, const char *name,
     {
       bool has_translatable = false;
       bool has_context = false;
-      const char *extracted_comment = NULL;
       const char **attp = attributes;
       while (*attp != NULL)
         {
           if (strcmp (attp[0], "translatable") == 0)
             has_translatable = (strcmp (attp[1], "yes") == 0);
           else if (strcmp (attp[0], "comments") == 0)
-            extracted_comment = attp[1];
+            comment_handler (NULL, 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)
-         : NULL);
     }
 
   /* In Glade 2, the attribute description="..." of <atkaction>
@@ -313,7 +310,7 @@ Missing context for the string extracted from '%s' element"),
   if (msgid != NULL)
     remember_a_message (mlp, msgctxt, msgid,
                         null_context, &pos,
-                        p->extracted_comment, savable_comment);
+                        NULL, savable_comment);
 }
 
 static void
@@ -328,7 +325,6 @@ start_element_gtkbuilder (struct element_state *p, const char *name,
   if (!p->extract_string)
     {
       bool has_translatable = false;
-      const char *extracted_comment = NULL;
       const char *extracted_context = NULL;
       const char **attp = attributes;
       while (*attp != NULL)
@@ -336,16 +332,12 @@ start_element_gtkbuilder (struct element_state *p, const char *name,
           if (strcmp (attp[0], "translatable") == 0)
             has_translatable = (strcmp (attp[1], "yes") == 0);
           else if (strcmp (attp[0], "comments") == 0)
-            extracted_comment = attp[1];
+            comment_handler (NULL, attp[1]);
           else if (strcmp (attp[0], "context") == 0)
             extracted_context = attp[1];
           attp += 2;
         }
       p->extract_string = has_translatable;
-      p->extracted_comment =
-        (has_translatable && extracted_comment != NULL
-         ? xstrdup (extracted_comment)
-         : NULL);
       p->extracted_context =
         (has_translatable && extracted_context != NULL
          ? xstrdup (extracted_context)
@@ -364,8 +356,7 @@ end_element_gtkbuilder (struct element_state *p, const char *name)
   if (p->buffer != NULL)
     {
       remember_a_message (mlp, p->extracted_context, p->buffer,
-                          null_context, &pos,
-                          p->extracted_comment, savable_comment);
+                          null_context, &pos, NULL, savable_comment);
       p->buffer = NULL;
       p->extracted_context = NULL;
     }
@@ -434,7 +425,6 @@ The root element <%s> is not allowed in a valid Glade file"),
   p = &stack[stack_depth];
   p->extract_string = extract_all;
   p->extract_context = false;
-  p->extracted_comment = NULL;
   p->extracted_context = NULL;
 
   element_parser->start_element (p, name, attributes);
@@ -468,8 +458,6 @@ end_element_handler (void *userData, const char *name)
     }
 
   /* Free memory for this stack level.  */
-  if (p->extracted_comment != NULL)
-    free (p->extracted_comment);
   if (p->extracted_context != NULL)
     free (p->extracted_context);
   if (p->buffer != NULL)
-- 
1.7.10.4

Reply via email to