bug-gettext
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gettext] Glade msgctxt patch


From: Daiki Ueno
Subject: [bug-gettext] Glade msgctxt patch
Date: Wed, 13 Mar 2013 13:37:46 +0900
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Replying to the old mail
<https://lists.gnu.org/archive/html/bug-gettext/2013-01/msg00030.html>.

Miguel Ángel <address@hidden> writes:

> Sorry, I was wrong. This patch implements the context extraction using
> 'arglist_parser_*' functions. Although, I would like to know this should
> work this way or not.

Well, sorry, I don't like it.  I didn't strongly suggest to use
arglist_parser_* functions, but just asked if there is any possibility
to avoid having a new function like split_glib_syntax_function, just to
split a string with '|' as a seperator.

Your initial attempt was rather better, but I no longer have the
original patch (because it has never posted here and your github repo
was rebased), so I recovered it from my memory and modified a bit.

(I know that the patch has small code dupes in xgettext.c and x-glade.c,
which I think acceptable.  And also it doesn't support GtkBuilder-style
context attribute yet, but I'd like to get things done step by step.)

Anyway, if there is no serious issue, I'll push it to git.

Regards,
-- 
Daiki Ueno
>From 4d20a0e573e1bbf802b84b8a33995cdd1d4ef737 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miguel=20=C3=81ngel=20Arruga=20Vivas?=
 <address@hidden>
Date: Wed, 30 Jan 2013 16:21:50 +0900
Subject: [PATCH] Extract msgctxt from Glade input files.

---
 gettext-tools/src/ChangeLog |  9 +++++++++
 gettext-tools/src/x-glade.c | 43 ++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 49 insertions(+), 3 deletions(-)

diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog
index c1d8ad4..184c78d 100644
--- a/gettext-tools/src/ChangeLog
+++ b/gettext-tools/src/ChangeLog
@@ -1,3 +1,12 @@
+2013-01-30  Miguel Ángel Arruga Vivas  <address@hidden>
+
+       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  <address@hidden>
 
        * 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);
         }
     }
 
-- 
1.8.1.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]