Hello.
We recently had the problem that line numbers in comments in our .pot
file were causing a lot of noise in our git repository. Every time a
source file changed, the next .pot file update would be full of changes
to line numbers, obscuring the actual changes to translatable strings.
At the same time, the file name in the comments is very helpful for our
translators, so if possible we would prefer not to disable location
comments entirely.
Disabling the line number portion but leaving the file name seems like a
very good solution. In our case, the file name almost always provides
the necessary context to the translator, and when it doesn't it is easy
enough to grep or text search in the indicated file to find the exact usage.
There appear to be a number of other people with the same problem, and
the popular but unsatisfactory solution seems to be to filter "#:"
comments out of the git-diff output. See
http://stackoverflow.com/questions/2006351/gettext-po-files-under-version-control
The gettext code already handles the case where a line number is
unavailable, so patching in an option to disable line numbers was trivial.
I used "--no-linenumbers" as the option name, because that was the first
thing I tried.
What do you think?
-- Tommy
>From 7bcc89670a667fae5ad8e73cb627d4602d1cf064 Mon Sep 17 00:00:00 2001
From: Tommy <[email protected]>
Date: Fri, 16 Aug 2013 01:40:53 +1200
Subject: [PATCH] xgettext: new option --no-linenumbers omits line numbers.
Unlike --no-location, the name of the originating file is retained.
---
gettext-tools/doc/xgettext.texi | 5 +++++
gettext-tools/src/read-catalog.h | 5 +++--
gettext-tools/src/xgettext.c | 5 ++++-
3 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/gettext-tools/doc/xgettext.texi b/gettext-tools/doc/xgettext.texi
index 1089e9c..1fad111 100644
--- a/gettext-tools/doc/xgettext.texi
+++ b/gettext-tools/doc/xgettext.texi
@@ -400,6 +400,11 @@ each message's context.
@opindex --add-location@r{, @code{xgettext} option}
Generate @samp{#: @var{filename}:@var{line}} lines (default).
+@item --no-linenumbers
+@opindex --no-linenumbers@r{, @code{xgettext} option}
+Omit the line numbers from @samp{#: @var{filename}:@var{line}} lines,
+including only the name(s) of the originating file(s).
+
@item --strict
@opindex --strict@r{, @code{xgettext} option}
Write out a strict Uniforum conforming PO file. Note that this
diff --git a/gettext-tools/src/read-catalog.h b/gettext-tools/src/read-catalog.h
index 8b77014..e22c612 100644
--- a/gettext-tools/src/read-catalog.h
+++ b/gettext-tools/src/read-catalog.h
@@ -167,8 +167,9 @@ extern default_catalog_reader_ty *
default_catalog_reader_alloc (default_catalog_reader_class_ty *method_table);
-/* If nonzero, remember comments for file name and line number for each
- msgid, if present in the reference input. Defaults to true. */
+/* If nonzero, remember comments for file name and/or line number for each
+ msgid, if present in the reference input. If 1, record both file name
+ and line number. If 2, record file name only. Defaults to 1. */
extern DLL_VARIABLE int line_comment;
/* If false, duplicate msgids in the same domain and file generate an error.
diff --git a/gettext-tools/src/xgettext.c b/gettext-tools/src/xgettext.c
index c6b8b0e..c8c1eaa 100644
--- a/gettext-tools/src/xgettext.c
+++ b/gettext-tools/src/xgettext.c
@@ -225,6 +225,7 @@ static const struct option long_options[] =
{ "msgstr-prefix", optional_argument, NULL, 'm' },
{ "msgstr-suffix", optional_argument, NULL, 'M' },
{ "no-escape", no_argument, NULL, 'e' },
+ { "no-linenumbers", no_argument, &line_comment, 2 },
{ "no-location", no_argument, &line_comment, 0 },
{ "no-wrap", no_argument, NULL, CHAR_MAX + 4 },
{ "omit-header", no_argument, &xgettext_omit_header, 1 },
@@ -2452,8 +2453,10 @@ meta information, not the empty string.\n")));
warn_format_string (is_format, mp->msgid, pos, "msgid");
/* Remember where we saw this msgid. */
- if (line_comment)
+ if (line_comment == 1)
message_comment_filepos (mp, pos->file_name, pos->line_number);
+ else if (line_comment == 2)
+ message_comment_filepos (mp, pos->file_name, (size_t)(-1));
/* Tell the lexer to reset its comment buffer, so that the next
message gets the correct comments. */
--
1.8.1.2