Permalink
Browse files

* Locale::Maketext::Extract::Plugin::Perl

   The Perl plugin now combines concatenated strings, eg
   loc('string' . ' and this')
   Contributed by Felix Ostmann

 * Locale::Maketext::Extract::Run
   Localised $_ correctly to avoid conflict with external strings
   Contributed by Sebastian Knapp

 * Locale::Maketext::Run
   Fixed bug http://rt.cpan.org/Ticket/Display.html?id=31940
   Debian bug http://bugs.debian.org/307777
   xgettext.pl -f was not chomping file names correctly
   Contributed by Niko Tyni
  • Loading branch information...
1 parent b2c656e commit d4112ecf8ff44a1238b4e0fa60ff149f6e3c4450 @clintongormley clintongormley committed Nov 22, 2008
Showing with 137 additions and 28 deletions.
  1. +3 −0 AUTHORS
  2. +17 −0 Changes
  3. +1 −0 MANIFEST
  4. +1 −1 lib/Locale/Maketext/Extract.pm
  5. +39 −26 lib/Locale/Maketext/Extract/Plugin/Perl.pm
  6. +1 −0 lib/Locale/Maketext/Extract/Run.pm
  7. +47 −1 t/5-extract.t
  8. +28 −0 t/55-runextract.t
View
@@ -11,6 +11,7 @@ Brian Cassidy (BRICAS)
Christian Hansen
Cosimo Streppone (COSIMO)
Clinton Gormley (DRTECH)
+Felix Ostmann
Gaal Yahas (GAAL)
Harmen
Helmut Lichtenberg
@@ -21,10 +22,12 @@ Joe McCarty
Macpaul Lin
Mathieu Arnold (MAT)
Mikael Sennerholm
+Niko Tyni
Noelle Christian
Robert Spier (ROBRT)
Ruslan U. Zakirov (RUZ)
Sava Chankov (SAVA)
+Sebastian Knapp
Sean M. Burke (SBURKE)
Stephen Quinney (SJQUINNEY)
Tatsuhiko Miyagawa (MIYAGAWA)
View
17 Changes
@@ -1,3 +1,20 @@
+[Changes for 0.74 - 2008-11-22]
+
+ * Locale::Maketext::Extract::Plugin::Perl
+ The Perl plugin now combines concatenated strings, eg
+ loc('string' . ' and this')
+ Contributed by Felix Ostmann
+
+ * Locale::Maketext::Extract::Run
+ Localised $_ correctly to avoid conflict with external strings
+ Contributed by Sebastian Knapp
+
+ * Locale::Maketext::Run
+ Fixed bug http://rt.cpan.org/Ticket/Display.html?id=31940
+ Debian bug http://bugs.debian.org/307777
+ xgettext.pl -f was not chomping file names correctly
+ Contributed by Niko Tyni
+
[Changes for 0.73 - 2008-10-28]
* Locale::Maketext::Extract::Plugin::TextTemplate
- renamed MyParser to Locale::Maketext::Extract::Plugin::TextTemplate::Parser
View
@@ -43,6 +43,7 @@ t/2-lmg.t
t/3-big-endian.t
t/4-encodings.t
t/5-extract.t
+t/55-runextract.t
t/6-gettext.t
t/7-comments.t
t/8-plugin-args.t
@@ -350,7 +350,7 @@ sub read_po {
my $header = '';
- local *LEXICON;
+ local (*LEXICON,$_);
open LEXICON, $file or die $!;
while (<LEXICON>) {
( 1 .. /^$/ ) or last;
@@ -19,7 +19,8 @@ Locale::Maketext::Extract::Plugin::Perl - Perl format parser
=head1 DESCRIPTION
-Extracts strings to localise (including HEREDOCS) from Perl code
+Extracts strings to localise (including HEREDOCS and
+concatenated strings) from Perl code.
=head1 SHORT PLUGIN NAME
@@ -81,10 +82,11 @@ sub extract {
my $self = shift;
local $_ = shift;
- local $SIG{__WARN__} = sub {die @_};
+ local $SIG{__WARN__} = sub { die @_ };
# Perl code:
- my ( $state, $str, $vars, $quo, $heredoc ) = (0);
+ my ( $state, $line_offset, $str, $str_part, $vars, $quo, $heredoc )
+ = ( 0, 0 );
my $orig = 1 + ( () = ( ( my $__ = $_ ) =~ /\n/g ) );
PARSER: {
@@ -102,27 +104,49 @@ PARSER: {
&& m/^([\S\(])\s*/gc
&& do { $state = ( ( $1 eq '(' ) ? PAR : NUL ); redo };
+ # concat
+ $state == PAR
+ && defined($str)
+ && m/^(\s*\.\s*)/gc
+ && do { $line_offset += ( () = ( ( my $__ = $1 ) =~ /\n/g ) ); redo };
+
+ # str_part
+ $state == PAR && defined($str_part) && do {
+ if ( ( $quo == QUO1 ) || ( $quo == QUO5 ) ) {
+ $str_part =~ s/\\([\\'])/$1/g
+ if ($str_part); # normalize q strings
+ }
+ elsif ( $quo != QUO6 ) {
+ $str_part =~ s/(\\(?:[0x]..|c?.))/"qq($1)"/eeg
+ if ($str_part); # normalize qq / qx strings
+ }
+ $str .= $str_part;
+ undef $str_part;
+ undef $quo;
+ redo;
+ };
+
# begin or end of string
$state == PAR && m/^(\')/gc && do { $state = $quo = QUO1; redo };
- $state == QUO1 && m/^([^'\\]+)/gc && do { $str .= $1; redo };
- $state == QUO1 && m/^((?:\\.)+)/gcs && do { $str .= $1; redo };
+ $state == QUO1 && m/^([^'\\]+)/gc && do { $str_part .= $1; redo };
+ $state == QUO1 && m/^((?:\\.)+)/gcs && do { $str_part .= $1; redo };
$state == QUO1 && m/^\'/gc && do { $state = PAR; redo };
$state == PAR && m/^\"/gc && do { $state = $quo = QUO2; redo };
- $state == QUO2 && m/^([^"\\]+)/gc && do { $str .= $1; redo };
- $state == QUO2 && m/^((?:\\.)+)/gcs && do { $str .= $1; redo };
+ $state == QUO2 && m/^([^"\\]+)/gc && do { $str_part .= $1; redo };
+ $state == QUO2 && m/^((?:\\.)+)/gcs && do { $str_part .= $1; redo };
$state == QUO2 && m/^\"/gc && do { $state = PAR; redo };
$state == PAR && m/^\`/gc && do { $state = $quo = QUO3; redo };
- $state == QUO3 && m/^([^\`]*)/gc && do { $str .= $1; redo };
+ $state == QUO3 && m/^([^\`]*)/gc && do { $str_part .= $1; redo };
$state == QUO3 && m/^\`/gc && do { $state = PAR; redo };
$state == PAR && m/^qq\{/gc && do { $state = $quo = QUO4; redo };
- $state == QUO4 && m/^([^\}]*)/gc && do { $str .= $1; redo };
+ $state == QUO4 && m/^([^\}]*)/gc && do { $str_part .= $1; redo };
$state == QUO4 && m/^\}/gc && do { $state = PAR; redo };
$state == PAR && m/^q\{/gc && do { $state = $quo = QUO5; redo };
- $state == QUO5 && m/^([^\}]*)/gc && do { $str .= $1; redo };
+ $state == QUO5 && m/^([^\}]*)/gc && do { $str_part .= $1; redo };
$state == QUO5 && m/^\}/gc && do { $state = PAR; redo };
# find heredoc terminator, then get the
@@ -154,35 +178,24 @@ PARSER: {
$state == HERE
&& m/^.*\r?\n/gc
&& s/\G(.*?\r?\n)$heredoc(\r?\n)//s
- && do { $state = PAR; $str .= $1; redo };
+ && do { $state = PAR; $str_part .= $1; $line_offset++; redo };
# end ()
#
$state == PAR && m/^\s*[\)]/gc && do {
$state = NUL;
$vars =~ s/[\n\r]//g if ($vars);
- if ($quo) {
- if ( ( $quo == QUO1 ) || ( $quo == QUO5 ) ) {
- $str =~ s/\\([\\'])/$1/g if ($str); # normalize q strings
- }
- elsif ( $quo != QUO6 ) {
- $str =~ s/(\\(?:[0x]..|c?.))/"qq($1)"/eeg
- if ($str); # normalize qq / qx strings
- }
- }
- # heredoc loosing the terminating line,
- #so decrement one more line for heredoc
$self->add_entry( $str,
- $line - ( () = $str =~ /\n/g ) - defined($heredoc),
- $vars )
- if ($str);
+ $line - ( () = $str =~ /\n/g ) - $line_offset,
+ $vars )
+ if $str;
undef $str;
undef $vars;
undef $heredoc;
+ $line_offset = 0;
redo;
};
-
# a line of vars
$state == PAR && m/^([^\)]*)/gc && do { $vars .= "$1\n"; redo };
}
@@ -58,6 +58,7 @@ sub run {
foreach my $file ( @{ $opts{f} || [] } ) {
open FILE, $file or die "Cannot open $file: $!";
while (<FILE>) {
+ chomp;
push @ARGV, $_ if -r and !-d;
}
}
View
@@ -1,7 +1,7 @@
#! /usr/bin/perl -w
use lib '../lib';
use strict;
-use Test::More tests => 95;
+use Test::More tests => 98;
use_ok('Locale::Maketext::Extract');
my $Ext = Locale::Maketext::Extract->new();
@@ -551,6 +551,52 @@ msgid "example2 %1\n"
msgstr ""
__EXPECTED__
+write_po_ok(<<'__EXAMPLE__' => <<'__EXPECTED__', "concat (heredoc)");
+_('exam'.<<"", 10)
+ple1 %1
+
+__EXAMPLE__
+#: :1
+#. (10)
+msgid "example1 %1\n"
+msgstr ""
+__EXPECTED__
+
+write_po_ok(<<'__EXAMPLE__' => <<'__EXPECTED__', "two _() calls with concat over multiline (heredoc)");
+_('example' .
+<<"", 10)
+1 %1
+
+_(<<"", 5)
+example2 %1
+
+__EXAMPLE__
+#: :1
+#. (10)
+msgid "example1 %1\n"
+msgstr ""
+
+#: :5
+#. (5)
+msgid "example2 %1\n"
+msgstr ""
+__EXPECTED__
+
+write_po_ok(<<'__EXAMPLE__' => <<'__EXPECTED__', "i can concat the world!");
+_(
+'\$foo'
+."\$bar"
+.<<''
+\$baz
+
+)
+__EXAMPLE__
+#: :2
+msgid "\\$foo$bar\\$baz\n"
+msgstr ""
+__EXPECTED__
+
+
sub extract_ok {
my ($text, $expected, $info, $verbatim) = @_;
$Ext->extract('' => $text);
View
@@ -0,0 +1,28 @@
+#! /usr/bin/perl -w
+use lib '../lib';
+use strict;
+use Test::More tests => 2;
+
+# test if the xgettext '-f' parameter stripts newlines from the filenames
+# http://bugs.debian.org/307777
+
+use_ok('Locale::Maketext::Extract::Run');
+
+my $inputfile = "$$.in";
+my $listfile = "$$.list";
+my $outfile = "$$.out";
+
+open(F, ">$inputfile") or die("create $inputfile failed: $!");
+print F "loc('test')";
+close F;
+
+open(F, ">$listfile") or die("create $inputfile failed: $!");
+print F "$inputfile\n/dev/null";
+close F;
+
+Locale::Maketext::Extract::Run::xgettext('-f', $listfile, '-o', $outfile);
+
+ok(-s $outfile, "non-empty output for Locale::Maketext::Extract::Run::xgettext");
+
+unlink $_ for ($inputfile, $listfile, $outfile);
+

0 comments on commit d4112ec

Please sign in to comment.