[Bps-public-commit] r14752 - in Locale-Maketext-Lexicon: . lib/Locale/Maketext lib/Locale/Maketext/Lexicon
jesse at bestpractical.com
jesse at bestpractical.com
Mon Aug 4 12:07:44 EDT 2008
Author: jesse
Date: Mon Aug 4 12:07:43 2008
New Revision: 14752
Added:
Locale-Maketext-Lexicon/t/7-comments.t
Locale-Maketext-Lexicon/t/comments.po
Modified:
Locale-Maketext-Lexicon/AUTHORS
Locale-Maketext-Lexicon/Changes
Locale-Maketext-Lexicon/MANIFEST
Locale-Maketext-Lexicon/README
Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm
Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Gettext.pm
Log:
* Applied patch from Cosimo Streppone to support round-tripping of commments in po files. [rt.cpan.org #5471]
Modified: Locale-Maketext-Lexicon/AUTHORS
==============================================================================
--- Locale-Maketext-Lexicon/AUTHORS (original)
+++ Locale-Maketext-Lexicon/AUTHORS Mon Aug 4 12:07:43 2008
@@ -8,6 +8,7 @@
Alain Barbet (ALIAN)
Brian Cassidy (BRICAS)
Christian Hansen
+Cosimo Streppone (COSIMO)
Gaal Yahas (GAAL)
Harmen
Helmut Lichtenberg
Modified: Locale-Maketext-Lexicon/Changes
==============================================================================
--- Locale-Maketext-Lexicon/Changes (original)
+++ Locale-Maketext-Lexicon/Changes Mon Aug 4 12:07:43 2008
@@ -1,3 +1,9 @@
+[Changes for 0.67 - .........]
+
+* Locale::Maketext::Extract: Support in Extract.pm and Lexicon/Gettext.pm
+ for parsing and keeping user comments in PO files.
+ Contributed by: Cosimo Streppone
+
[Changes for 0.66 - 2008-02-12]
* Locale::Maketext::Extract: Support in Extract.pm->extract for
Modified: Locale-Maketext-Lexicon/MANIFEST
==============================================================================
--- Locale-Maketext-Lexicon/MANIFEST (original)
+++ Locale-Maketext-Lexicon/MANIFEST Mon Aug 4 12:07:43 2008
@@ -34,6 +34,7 @@
t/4-encodings.t
t/5-extract.t
t/6-gettext.t
+t/7-comments.t
t/99-bug-import-for-subclasses.t
t/gencat.m
t/locale/en/LC_MESSAGES/test.mo
@@ -45,6 +46,7 @@
t/locale/zh_TW/LC_MESSAGES/test.mo
t/locale/zh_TW/LC_MESSAGES/test_be.mo
t/locale/zh_TW/LC_MESSAGES/test_utf8.mo
+t/comments.po
t/messages.mo
t/messages.po
t/T_L10N.pm
Modified: Locale-Maketext-Lexicon/README
==============================================================================
--- Locale-Maketext-Lexicon/README (original)
+++ Locale-Maketext-Lexicon/README Mon Aug 4 12:07:43 2008
@@ -2,8 +2,8 @@
Locale::Maketext::Lexicon - Use other catalog formats in Maketext
VERSION
- This document describes version 0.66 of Locale::Maketext::Lexicon,
- released February 12, 2008.
+ This document describes version 0.67 of Locale::Maketext::Lexicon,
+ released ...............
SYNOPSIS
As part of a localization class, automatically glob for available
Modified: Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm
==============================================================================
--- Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm (original)
+++ Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm Mon Aug 4 12:07:43 2008
@@ -115,6 +115,7 @@
sub clear {
$_[0]->set_header;
$_[0]->set_lexicon;
+ $_[0]->set_comments;
$_[0]->set_entries;
$_[0]->set_compiled_entries;
}
@@ -140,18 +141,31 @@
$self->set_header("$header\n");
require Locale::Maketext::Lexicon::Gettext;
- my $lexicon = (
- defined($_)
- ? Locale::Maketext::Lexicon::Gettext->parse($_, <LEXICON>)
- : {}
- );
+ my $lexicon = {};
+ my $comments = {};
+
+ if (defined($_)) {
+ ($lexicon, $comments) = Locale::Maketext::Lexicon::Gettext->parse($_, <LEXICON>);
+ }
# Internally the lexicon is in gettext format already.
$self->set_lexicon( { map _maketext_to_gettext($_), %$lexicon } );
+ $self->set_comments( $comments );
close LEXICON;
}
+sub msg_comment {
+ my $self = shift;
+ my $msgid = shift;
+ my $comment = $self->{comments}->{$msgid};
+ return $comment;
+}
+
+sub set_comments {
+ $_[0]->{comments}=$_[1];
+}
+
=head3 method write_po ($file, $add_format_marker?)
=cut
@@ -167,6 +181,10 @@
foreach my $msgid ($self->msgids) {
$self->normalize_space($msgid);
print LEXICON "\n";
+ if (my $comment = $self->msg_comment($msgid)) {
+ my @lines = split "\n", $comment;
+ print LEXICON map {"# $_\n"} @lines;
+ }
print LEXICON $self->msg_positions($msgid);
print LEXICON $self->msg_variables($msgid);
print LEXICON $self->msg_format($msgid) if $add_format_marker;
Modified: Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Gettext.pm
==============================================================================
--- Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Gettext.pm (original)
+++ Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Gettext.pm Mon Aug 4 12:07:43 2008
@@ -94,6 +94,7 @@
my $self = shift;
my (%var, $key, @ret);
my @metadata;
+ my @comments;
$InputEncoding = $OutputEncoding = $DoEncoding = undef;
@@ -116,8 +117,11 @@
elsif ($AllowEmpty) {
push @ret, (transform($var{msgid}), '');
}
- push @metadata, parse_metadata($var{msgstr})
- if $var{msgid} eq '';
+ if ($var{msgid} eq '') {
+ push @metadata, parse_metadata($var{msgstr});
+ } else {
+ push @comments, transform($var{msgid}), $var{msgcomment};
+ }
%var = ();
};
@@ -138,6 +142,12 @@
}
:
+ /^# (.*)$/
+ ? do { # user comments
+ $var{msgcomment} .= $1 . "\n";
+ }
+ :
+
/^#, +(.*) *$/
? do { # control variables
$var{$_} = 1 for split(/,\s+/, $1);
@@ -149,6 +159,7 @@
$process->($_);
}
: ();
+
}
# do not silently skip last entry
@@ -159,7 +170,11 @@
push @metadata, parse_metadata($var{msgstr})
if $var{msgid} eq '';
- return { @metadata, @ret };
+ return wantarray
+ ? ( { @metadata, @ret }, { @comments } )
+ : ( { @metadata, @ret } )
+ ;
+
}
sub parse_metadata {
Added: Locale-Maketext-Lexicon/t/7-comments.t
==============================================================================
--- (empty file)
+++ Locale-Maketext-Lexicon/t/7-comments.t Mon Aug 4 12:07:43 2008
@@ -0,0 +1,43 @@
+#!/usr/bin/perl -w
+#
+# Check that comments in PO files are correctly parsed
+#
+
+use strict;
+use Test::More tests => 6;
+
+use_ok('Locale::Maketext::Extract');
+
+my $msgid = 'A random string to check that comments work';
+my $lex = Locale::Maketext::Extract->new();
+ok( $lex, 'Locale::Maketext::Extract object created');
+
+$lex->read_po('t/comments.po');
+
+# Here '#' and newlines are kept together with the comment
+# Don't know if it's correct or elegant
+is(
+ $lex->msg_comment($msgid),
+ 'Some user comment' . "\n"
+);
+
+$lex->write_po('t/comments_out.po');
+
+$lex->clear();
+
+is(
+ $lex->msg_comment($msgid),
+ undef,
+ 'Comment should be gone with clear()'
+);
+
+# Read back the new po file and check that
+# the comment is readable again
+$lex->read_po('t/comments_out.po');
+
+is(
+ $lex->msg_comment($msgid),
+ 'Some user comment' . "\n"
+);
+
+ok(unlink('t/comments_out.po'));
Added: Locale-Maketext-Lexicon/t/comments.po
==============================================================================
--- (empty file)
+++ Locale-Maketext-Lexicon/t/comments.po Mon Aug 4 12:07:43 2008
@@ -0,0 +1,15 @@
+msgid ""
+msgstr ""
+"Project-Id-Version: Test App 0.01\n"
+"POT-Creation-Date: 2008-08-01 14:20+0200\n"
+"PO-Revision-Date: 2008-08-01 14:21+0200\n"
+"Last-Translator: <cosimo at cpan.org>\n"
+"Language-Team: Italian <cosimo at cpan.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+# Some user comment
+#: comments.t:1
+msgid "A random string to check that comments work"
+msgstr "Una stringa casuale per controllare che i commenti funzionino"
More information about the Bps-public-commit
mailing list