[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gettext] [PATCH 2/3] i18n: Only extract comments marked by spec
From: |
Daiki Ueno |
Subject: |
Re: [bug-gettext] [PATCH 2/3] i18n: Only extract comments marked by special tag |
Date: |
Mon, 21 Apr 2014 13:48:06 +0900 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Hi Jiang,
Jiang Xin <address@hidden> writes:
> 3. Hack the parser for comments in "gettext-tools/src/x-c.c" (maybe
> function phase4_getc()) to support various multi-line comments style,
> such as:
>
> /*
> * TRANSLATORS: this comment is to help you, but it is
> * a lot longer to fit on just a single line.
> */
>
> /*
> ** TRANSLATORS: this comment is to help you, but it is
> ** a lot longer to fit on just a single line.
> */
>
> /********************************************************
> * TRANSLATORS: this comment is to help you, but it is *
> * a lot longer to fit on just a single line. *
> ********************************************************/
For the first two examples, I think it should be actually possible in a
similar way as Emacs recognizes the "Local variables:" comment block.
That is, if we see the comment tag ("TRANSLATORS:" here) and it is
prefixed by a string ("* " or "** "), then discard it from all other
lines.
I'm attaching a patch.
Regards,
--
Daiki Ueno
>From ae4c23887773e0eff42d47c575199d1b75096c56 Mon Sep 17 00:00:00 2001
From: Daiki Ueno <address@hidden>
Date: Mon, 21 Apr 2014 13:32:00 +0900
Subject: [PATCH] xgettext: Recognize comment tag prefix
Reported by Jiang Xin in
<http://article.gmane.org/gmane.comp.version-control.git/246462>.
* xgettext.c (remember_a_message): Discard a string prefixed to the comment
tag from all remaining comment lines.
---
gettext-tools/src/xgettext.c | 34 +++++++++++++++++++++++++++-------
1 file changed, 27 insertions(+), 7 deletions(-)
diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c
index 42fdc31..c07a9e8 100644
--- a/gettext-tools/src/xgettext.c
+++ b/gettext-tools/src/xgettext.c
@@ -2294,6 +2294,11 @@ meta information, not the empty string.\n")));
size_t nitems_after;
int j;
bool add_all_remaining_comments;
+ /* The string before the comment tag. For example, If "** TRANSLATORS:"
+ is seen and the comment tag is "TRANSLATORS:",
+ then comment_tag_prefix is set to "** ". */
+ char *comment_tag_prefix;
+ size_t comment_tag_prefix_length;
nitems_before = (mp->comment_dot != NULL ? mp->comment_dot->nitems : 0);
@@ -2372,13 +2377,28 @@ meta information, not the empty string.\n")));
if (interesting)
continue;
}
- /* When the comment tag is seen, it drags in not only the line
- which it starts, but all remaining comment lines. */
- if (add_all_remaining_comments
- || (add_all_remaining_comments =
- (comment_tag != NULL
- && strncmp (s, comment_tag, strlen (comment_tag)) == 0)))
- message_comment_dot_append (mp, s);
+
+ if (add_all_remaining_comments)
+ {
+ if (strncmp (s, comment_tag_prefix, comment_tag_prefix_length) ==
0)
+ message_comment_dot_append (mp, s + comment_tag_prefix_length);
+ else
+ /* If the line does not start with the comment tag
+ prefix, finish the multi-line #. comment block. */
+ add_all_remaining_comments = false;
+ }
+ if (!add_all_remaining_comments && comment_tag != NULL)
+ {
+ /* When the comment tag is seen, it drags in not only the line
+ which it starts, but all remaining comment lines. */
+ if ((t = c_strstr (s, comment_tag)) != NULL)
+ {
+ add_all_remaining_comments = true;
+ comment_tag_prefix = s;
+ comment_tag_prefix_length = t - s;
+ message_comment_dot_append (mp, s + comment_tag_prefix_length);
+ }
+ }
}
nitems_after = (mp->comment_dot != NULL ? mp->comment_dot->nitems : 0);
--
1.9.0