Subject: | comments in po-files |
Hi,
We are using comments in po-files like this:
#: /some/file:77
# Changed at 1077894033
# Changed by herald
msgid "some id"
msgstr "some translation"
after running "xgettext.pl -u -o po-file.po *", all comments are wiped out.
To avoid this I made attached patch. It's probably not the most elegant solution, but for now it works.
Could you please prevent the wiping out of comments in po-files in future releases of this module?
Thanks in advance,
Herald
diff -ruN Locale-Maketext-Lexicon-0.34/lib/Locale/Maketext/Extract.pm Locale-Maketext-Lexicon-new/lib/Locale/Maketext/Extract.pm
--- Locale-Maketext-Lexicon-0.34/lib/Locale/Maketext/Extract.pm 2003-12-31 09:28:19.000000000 +0100
+++ Locale-Maketext-Lexicon-new/lib/Locale/Maketext/Extract.pm 2004-02-27 16:36:47.000000000 +0100
@@ -66,7 +66,7 @@
sub new {
my $class = shift;
- bless({ header => '', entries => {}, lexicon => {}, @_ }, $class);
+ bless({ header => '', entries => {}, lexicon => {}, comments => {}, @_ }, $class);
}
=head2 Accessors
@@ -87,6 +87,12 @@
sub msgstr { $_[0]{lexicon}{$_[1]} }
sub set_msgstr { $_[0]{lexicon}{$_[1]} = $_[2] }
+sub comments { $_[0]{comments} }
+sub set_comments { $_[0]{comments} = $_[1] || {} }
+
+sub comment { $_[0]{comments}{$_[1]} }
+sub set_comment { $_[0]{comments}{$_[1]} = $_[2] || [] }
+
sub entries { $_[0]{entries} }
sub set_entries { $_[0]{entries} = $_[1] || {} }
@@ -122,11 +128,12 @@
$self->set_header("$header\n");
require Locale::Maketext::Lexicon::Gettext;
- my $lexicon = Locale::Maketext::Lexicon::Gettext->parse(<LEXICON>);
+ my ($comments, $lexicon) = Locale::Maketext::Lexicon::Gettext->parse(<LEXICON>);
$self->set_lexicon(
$verbatim ? { map _to_gettext($_), %$lexicon } : $lexicon
);
+ $self->set_comments($comments);
close LEXICON;
}
@@ -142,6 +149,7 @@
$self->normalize_space($msgid);
print LEXICON "\n";
print LEXICON $self->msg_positions($msgid);
+ print LEXICON $self->msg_comments($msgid);
print LEXICON $self->msg_variables($msgid);
print LEXICON $self->msg_format($msgid) if $add_format;
print LEXICON $self->msg_out($msgid);
@@ -345,6 +353,11 @@
return join('', '#:', sort(keys %files), "\n");
}
+sub msg_comments {
+ my ($self, $msgid) = @_;
+ return join('', map { "# " . $_ . "\n" } @{$self->comment($msgid)||[]});
+}
+
sub msg_variables {
my ($self, $msgid) = @_;
my $out = '';
diff -ruN Locale-Maketext-Lexicon-0.34/lib/Locale/Maketext/Lexicon/Gettext.pm Locale-Maketext-Lexicon-new/lib/Locale/Maketext/Lexicon/Gettext.pm
--- Locale-Maketext-Lexicon-0.34/lib/Locale/Maketext/Lexicon/Gettext.pm 2003-12-31 09:28:19.000000000 +0100
+++ Locale-Maketext-Lexicon-new/lib/Locale/Maketext/Lexicon/Gettext.pm 2004-02-27 16:37:01.000000000 +0100
@@ -84,6 +84,8 @@
my $self = shift;
my (%var, $key, @ret);
my @metadata;
+ my %comments;
+ my @comments;
$InputEncoding = $OutputEncoding = $DoEncoding = undef;
@@ -106,6 +108,10 @@
/^(msgid|msgstr) +"(.*)" *$/ ? do { # leading strings
$var{$1} = $2;
$key = $1;
+ if ($key eq 'msgstr' && scalar(@comments > 0)) {
+ $comments{$var{msgid}} = [@comments];
+ undef @comments;
+ }
} :
/^"(.*)" *$/ ? do { # continued strings
@@ -115,6 +121,10 @@
/^#, +(.*) *$/ ? do { # control variables
$var{$_} = 1 for split(/,\s+/, $1);
} :
+
+ /^#[ \t]+(.*) *$/ ? do { # comment
+ push(@comments, $1);
+ } :
/^ *$/ && %var ? do { # interpolate string escapes
push @ret, (map transform($_), @var{'msgid', 'msgstr'})
@@ -125,12 +135,11 @@
} : ();
}
- push @ret, map { transform($_) } @var{'msgid', 'msgstr'}
- if length $var{msgstr};
+ push @ret, map { transform($_) } @var{'msgid', 'msgstr'}
+ if (length $var{msgstr});
push @metadata, parse_metadata($var{msgstr})
if $var{msgid} eq '';
-
- return {@metadata, @ret};
+ return (\%comments, {@metadata, @ret});
}
sub parse_metadata {