[Bps-public-commit] r16994 - in Locale-Maketext-Lexicon/trunk: . lib/Locale/Maketext lib/Locale/Maketext/Extract t

clint at bestpractical.com clint at bestpractical.com
Sat Nov 22 15:29:19 EST 2008


Author: clint
Date: Sat Nov 22 15:29:19 2008
New Revision: 16994

Added:
   Locale-Maketext-Lexicon/trunk/t/55-runextract.t
Modified:
   Locale-Maketext-Lexicon/trunk/   (props changed)
   Locale-Maketext-Lexicon/trunk/AUTHORS
   Locale-Maketext-Lexicon/trunk/Changes
   Locale-Maketext-Lexicon/trunk/MANIFEST
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract.pm
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/Perl.pm
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Run.pm
   Locale-Maketext-Lexicon/trunk/t/5-extract.t

Log:
 * 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


Modified: Locale-Maketext-Lexicon/trunk/AUTHORS
==============================================================================
--- Locale-Maketext-Lexicon/trunk/AUTHORS	(original)
+++ Locale-Maketext-Lexicon/trunk/AUTHORS	Sat Nov 22 15:29:19 2008
@@ -11,6 +11,7 @@
 Christian Hansen
 Cosimo Streppone        (COSIMO)
 Clinton Gormley         (DRTECH)
+Felix Ostmann
 Gaal Yahas              (GAAL)
 Harmen
 Helmut Lichtenberg
@@ -21,10 +22,12 @@
 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)

Modified: Locale-Maketext-Lexicon/trunk/Changes
==============================================================================
--- Locale-Maketext-Lexicon/trunk/Changes	(original)
+++ Locale-Maketext-Lexicon/trunk/Changes	Sat Nov 22 15:29:19 2008
@@ -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

Modified: Locale-Maketext-Lexicon/trunk/MANIFEST
==============================================================================
--- Locale-Maketext-Lexicon/trunk/MANIFEST	(original)
+++ Locale-Maketext-Lexicon/trunk/MANIFEST	Sat Nov 22 15:29:19 2008
@@ -43,6 +43,7 @@
 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

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract.pm	Sat Nov 22 15:29:19 2008
@@ -350,7 +350,7 @@
 
     my $header = '';
 
-    local *LEXICON;
+    local (*LEXICON,$_);
     open LEXICON, $file or die $!;
     while (<LEXICON>) {
         ( 1 .. /^$/ ) or last;

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/Perl.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/Perl.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/Perl.pm	Sat Nov 22 15:29:19 2008
@@ -19,7 +19,8 @@
 
 =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 @@
     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 @@
             && 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,7 +178,7 @@
         $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 ()
         #
@@ -162,27 +186,16 @@
         $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 };
     }

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Run.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Run.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Run.pm	Sat Nov 22 15:29:19 2008
@@ -58,6 +58,7 @@
     foreach my $file ( @{ $opts{f} || [] } ) {
         open FILE, $file or die "Cannot open $file: $!";
         while (<FILE>) {
+            chomp;
             push @ARGV, $_ if -r and !-d;
         }
     }

Modified: Locale-Maketext-Lexicon/trunk/t/5-extract.t
==============================================================================
--- Locale-Maketext-Lexicon/trunk/t/5-extract.t	(original)
+++ Locale-Maketext-Lexicon/trunk/t/5-extract.t	Sat Nov 22 15:29:19 2008
@@ -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 @@
 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);

Added: Locale-Maketext-Lexicon/trunk/t/55-runextract.t
==============================================================================
--- (empty file)
+++ Locale-Maketext-Lexicon/trunk/t/55-runextract.t	Sat Nov 22 15:29:19 2008
@@ -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);
+



More information about the Bps-public-commit mailing list