r24502 - in /branches/upstream/liblocale-maketext-lexicon-perl/current: Changes SIGNATURE lib/Locale/Maketext/Extract.pm lib/Locale/Maketext/Lexicon.pm t/5-extract.t

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Sat Aug 23 15:32:26 UTC 2008


Author: gregoa
Date: Sat Aug 23 15:32:22 2008
New Revision: 24502

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=24502
Log:
[svn-upgrade] Integrating new upstream version, liblocale-maketext-lexicon-perl (0.68)

Modified:
    branches/upstream/liblocale-maketext-lexicon-perl/current/Changes
    branches/upstream/liblocale-maketext-lexicon-perl/current/SIGNATURE
    branches/upstream/liblocale-maketext-lexicon-perl/current/lib/Locale/Maketext/Extract.pm
    branches/upstream/liblocale-maketext-lexicon-perl/current/lib/Locale/Maketext/Lexicon.pm
    branches/upstream/liblocale-maketext-lexicon-perl/current/t/5-extract.t

Modified: branches/upstream/liblocale-maketext-lexicon-perl/current/Changes
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liblocale-maketext-lexicon-perl/current/Changes?rev=24502&op=diff
==============================================================================
--- branches/upstream/liblocale-maketext-lexicon-perl/current/Changes (original)
+++ branches/upstream/liblocale-maketext-lexicon-perl/current/Changes Sat Aug 23 15:32:22 2008
@@ -1,3 +1,10 @@
+
+[Changes for 0.68 - 2008-08-18]
+
+* Locale::Maketext::Extract: Support for other forms of localization in 
+  TT templates and TT HEREDOCS.
+  Contributed by: Felix Antonius Wilhelm Ostmann
+
 [Changes for 0.67 - 2008-08-04]
 
 * Locale::Maketext::Extract: Support in Extract.pm and Lexicon/Gettext.pm

Modified: branches/upstream/liblocale-maketext-lexicon-perl/current/SIGNATURE
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liblocale-maketext-lexicon-perl/current/SIGNATURE?rev=24502&op=diff
==============================================================================
--- branches/upstream/liblocale-maketext-lexicon-perl/current/SIGNATURE (original)
+++ branches/upstream/liblocale-maketext-lexicon-perl/current/SIGNATURE Sat Aug 23 15:32:22 2008
@@ -15,7 +15,7 @@
 Hash: SHA1
 
 SHA1 fc252c495595a771e93f5a399dc0c3467dd1dbfd AUTHORS
-SHA1 48fa296e725ffed4734b7783b56d1065c7f79146 Changes
+SHA1 f24aa41ce543b1f43d169e6934f5809678283cd2 Changes
 SHA1 aceae4714f2f2dc94c0d5e28b22ff3bc7a0c05ae MANIFEST
 SHA1 ff64a729c6469e1d1ce8edccb4072672bdce4d17 MANIFEST.SKIP
 SHA1 356a68dfc6427c163ecc377b18e8e01584209447 META.yml
@@ -38,9 +38,9 @@
 SHA1 15260d018c2f7dd0dc9705a621684149742e7a5f inc/Test/Builder/Module.pm
 SHA1 0b8387e071b32d2d595715e303e18c3d4579ca33 inc/Test/More.pm
 SHA1 a3b43f30a4aa19adb8cda1ceaf5b19da0a5e1cae inc/attributes.pm
-SHA1 c4dc4784071672c0219610781148eb3e39ee2f57 lib/Locale/Maketext/Extract.pm
+SHA1 5a7cd466299257b71bef50aaf30190688666e7ec lib/Locale/Maketext/Extract.pm
 SHA1 ae1c100252e17e5963a0e07a1505746d3e851515 lib/Locale/Maketext/Extract/Run.pm
-SHA1 653380897e102c66167fcdeacb129a86700f69e8 lib/Locale/Maketext/Lexicon.pm
+SHA1 3d989e0d2384244be42eeb402a12f78f6a799377 lib/Locale/Maketext/Lexicon.pm
 SHA1 6d18ec954610e5bef54e3521dc57db781aee84e2 lib/Locale/Maketext/Lexicon/Auto.pm
 SHA1 90e71ed81f8c69e6263df5fdfdef379bf0a6bfc2 lib/Locale/Maketext/Lexicon/Gettext.pm
 SHA1 aa70e8728c63c0165aea0280e85b8db7be70650f lib/Locale/Maketext/Lexicon/Msgcat.pm
@@ -50,7 +50,7 @@
 SHA1 812a92de30302293470bb12512fdb9b4e0271f4c t/2-lmg.t
 SHA1 2e6e1f69fef9c3868bc2d9d323888ef843851e73 t/3-big-endian.t
 SHA1 07e68cea617f91bb9dbbd9ce0b8fdd0a486f3125 t/4-encodings.t
-SHA1 0305386868418e95ba3ceebadb1299aa744ed433 t/5-extract.t
+SHA1 311294a744904066fb5f367cd566300239961003 t/5-extract.t
 SHA1 00c15dd4ee62792ab292386b641194fad9d1bf11 t/6-gettext.t
 SHA1 142639c38f04d8c5104f44015b71a7737b56603f t/7-comments.t
 SHA1 ce5c72c3bc2c78bbf8da1a0d73b08523c5d03025 t/99-bug-import-for-subclasses.t
@@ -71,7 +71,7 @@
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.9 (Darwin)
 
-iEYEARECAAYFAkiXLFwACgkQEi9d9xCOQEZWUACgtH+/HZcs08myXwzj5eS+8D3k
-1kIAoMKz+GpJceNWCULWbo+0S4XoEyVu
-=aj9i
+iEYEARECAAYFAkipcOsACgkQEi9d9xCOQEb38gCdF8w/BVgREIlJ6vpEKkcJfymq
+91kAoIhgdXQe8GAf4UPZb08w1Seh+Jz7
+=NvJd
 -----END PGP SIGNATURE-----

Modified: branches/upstream/liblocale-maketext-lexicon-perl/current/lib/Locale/Maketext/Extract.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liblocale-maketext-lexicon-perl/current/lib/Locale/Maketext/Extract.pm?rev=24502&op=diff
==============================================================================
--- branches/upstream/liblocale-maketext-lexicon-perl/current/lib/Locale/Maketext/Extract.pm (original)
+++ branches/upstream/liblocale-maketext-lexicon-perl/current/lib/Locale/Maketext/Extract.pm Sat Aug 23 15:32:22 2008
@@ -202,11 +202,14 @@
 use constant NUL  => 0;
 use constant BEG  => 1;
 use constant PAR  => 2;
+use constant HERE =>10;
 use constant QUO1 => 3;
 use constant QUO2 => 4;
 use constant QUO3 => 5;
 use constant QUO4 => 6;
 use constant QUO5 => 7;
+use constant QUO6 => 8;
+use constant QUO7 => 9;
 
 sub extract {
     my $self = shift;
@@ -252,11 +255,13 @@
 
     # Template Toolkit
     $line = 1; pos($_) = 0;
-    while (m!\G(.*?\[%\s*\|l(?:oc)?(.*?)\s*%\](.*?)\[%\s*END\s*%\])!sg) {
-        my ($vars, $str) = ($2, $3);
+    while (m!\G(.*?\[%-?\s*\|l(?:oc)?(.*?)\s*(-?)%\](.*?)\[%(-?)\s*END\s*-?%\])!sg) { 
+        my ($vars, $trim_start, $str, $trim_end) = ($2, $3, $4, $5);
         $line += ( () = ($1 =~ /\n/g) ); # cryptocontext!
         $vars =~ s/^\s*\(//;
         $vars =~ s/\)\s*$//;
+        $trim_start && $str =~ s/^\s+//;
+        $trim_end   && $str =~ s/\s+$//;
         $self->add_entry($str, [ $file, $line, $vars ]);
     }
 
@@ -300,7 +305,7 @@
     }
 
     # Perl code:
-    my ($state,$str,$vars,$quo)=(0);
+    my ($state,$str,$vars,$quo,$heredoc)=(0);
     pos($_) = 0;
     my $orig = 1 + (() = ((my $__ = $_) =~ /\n/g));
 
@@ -341,6 +346,22 @@
         $state == QUO5 && m/^([^\}]*)/gc    && do { $str  .= $1;            redo };
         $state == QUO5 && m/^\}/gc          && do { $state = PAR;           redo };
 
+        # find heredoc terminator, then get the heredoc and go back to current position
+        $state == PAR  && m/^<<\s*\'/gc     && do { $state    = $quo = QUO6; $heredoc = '';    redo };
+        $state == QUO6 && m/^([^'\\\n]+)/gc && do { $heredoc .= $1;                            redo };
+        $state == QUO6 && m/^((?:\\.)+)/gc  && do { $heredoc .= $1;                            redo };
+        $state == QUO6 && m/^\'/gc          && do { $state    = HERE; $heredoc =~ s/\\\'/\'/g; redo };
+
+        $state == PAR  && m/^<<\s*\"/gc     && do { $state    = $quo = QUO7; $heredoc = '';    redo };
+        $state == QUO7 && m/^([^"\\\n]+)/gc && do { $heredoc .= $1;                            redo };
+        $state == QUO7 && m/^((?:\\.)+)/gc  && do { $heredoc .= $1;                            redo };
+        $state == QUO7 && m/^\"/gc          && do { $state    = HERE; $heredoc =~ s/\\\"/\"/g; redo };
+
+        $state == PAR  && m/^<<(\w*)/gc     && do { $state = HERE; $quo = QUO7; $heredoc = $1; redo };
+
+        # jump ahaid and get the heredoc, then s/// also reset the pos and we are back at the current pos
+        $state == HERE && m/^.*\r?\n/gc     && s/\G(.*?\r?\n)$heredoc(\r?\n)//s && do { $state = PAR; $str .= $1; redo };
+
         # end ()
         #
         
@@ -348,13 +369,14 @@
             $state = NUL; 
             $vars =~ s/[\n\r]//g if ($vars);
             if (($quo == QUO1) || ($quo == QUO5) ){
-                $str =~ s/\\([\\'])/$1/g; # normalize q strings
+                $str =~ s/\\([\\'])/$1/g if ($str); # normalize q strings
             }
-            else {
-                $str =~ s/(\\(?:[0x]..|c?.))/"qq($1)"/eeg; # normalize qq / qx strings
+            elsif ($quo != QUO6) {
+                $str =~ s/(\\(?:[0x]..|c?.))/"qq($1)"/eeg if ($str); # normalize qq / qx strings
             }
-            push @{$entries->{$str}}, [ $file, $line - (() = $str =~ /\n/g), $vars] if ($str);
-            undef $str; undef $vars;
+            # heredoc loosing the terminating line, so decrement one more line for heredoc
+            push @{$entries->{$str}}, [ $file, $line - (() = $str =~ /\n/g) - defined($heredoc), $vars] if ($str);
+            undef $str; undef $vars; undef $heredoc;
             redo;
         };
 

Modified: branches/upstream/liblocale-maketext-lexicon-perl/current/lib/Locale/Maketext/Lexicon.pm
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liblocale-maketext-lexicon-perl/current/lib/Locale/Maketext/Lexicon.pm?rev=24502&op=diff
==============================================================================
--- branches/upstream/liblocale-maketext-lexicon-perl/current/lib/Locale/Maketext/Lexicon.pm (original)
+++ branches/upstream/liblocale-maketext-lexicon-perl/current/lib/Locale/Maketext/Lexicon.pm Sat Aug 23 15:32:22 2008
@@ -1,5 +1,5 @@
 package Locale::Maketext::Lexicon;
-$Locale::Maketext::Lexicon::VERSION = '0.67';
+$Locale::Maketext::Lexicon::VERSION = '0.68';
 
 use 5.004;
 use strict;
@@ -10,8 +10,8 @@
 
 =head1 VERSION
 
-This document describes version 0.67 of Locale::Maketext::Lexicon,
-released August 4, 2008.
+This document describes version 0.68 of Locale::Maketext::Lexicon,
+released August 18, 2008.
 
 =head1 SYNOPSIS
 

Modified: branches/upstream/liblocale-maketext-lexicon-perl/current/t/5-extract.t
URL: http://svn.debian.org/wsvn/pkg-perl/branches/upstream/liblocale-maketext-lexicon-perl/current/t/5-extract.t?rev=24502&op=diff
==============================================================================
--- branches/upstream/liblocale-maketext-lexicon-perl/current/t/5-extract.t (original)
+++ branches/upstream/liblocale-maketext-lexicon-perl/current/t/5-extract.t Sat Aug 23 15:32:22 2008
@@ -1,7 +1,7 @@
 #! /usr/bin/perl -w
 use lib '../lib';
 use strict;
-use Test::More tests => 29;
+use Test::More tests => 43;
 
 use_ok('Locale::Maketext::Extract');
 my $Ext = Locale::Maketext::Extract->new;
@@ -57,6 +57,121 @@
         => 'I\'ll poke you like a "cow" man.',
     "Handle escaped double quotes"
 );
+
+extract_ok(q(_("","car"))                  => '',            'ignore empty string');
+extract_ok(q(_("0"))                       => '',            'ignore zero');
+
+extract_ok(<<'__EXAMPLE__'                 => 'foo bar baz',   'trim the string (tt)');
+[% |loc -%]
+foo bar baz
+[%- END %]
+__EXAMPLE__
+
+extract_ok(<<'__EXAMPLE__'                 => "123\n",       "Simple extraction (heredoc)");
+_(<<__LOC__);
+123
+__LOC__
+__EXAMPLE__
+
+extract_ok(<<'__EXAMPLE__'                 => "foo\\\$bar\\\'baz\n", "No escaped of \$ and \' in singlequoted terminator (heredoc)");
+_(<<'__LOC__');
+foo\$bar\'baz
+__LOC__
+__EXAMPLE__
+
+extract_ok(<<'__EXAMPLE__'                 => "foo\$bar\n",  "Normalized \$ in doublequoted terminator (heredoc)");
+_(<<"__LOC__");
+foo\$bar
+__LOC__
+__EXAMPLE__
+
+extract_ok(<<'__EXAMPLE__'                 => "foo\nbar\n",  "multilines (heredoc)");
+_(<<__LOC__);
+foo
+bar
+__LOC__
+__EXAMPLE__
+
+extract_ok(<<'__EXAMPLE__'                 => "example\n",   "null identifier (heredoc)");
+_(<<"");
+example
+
+__EXAMPLE__
+
+extract_ok(<<'__EXAMPLE__'                 => "example\n",   "end() after the heredoc (heredoc)");
+_(<<__LOC__
+example
+__LOC__
+);
+__EXAMPLE__
+
+write_po_ok(<<'__EXAMPLE__'                => <<'__EXPECTED__', "null identifier with end after the heredoc (heredoc)");
+_(<<""
+example
+
+);
+__EXAMPLE__
+#: :1
+msgid "example\n"
+msgstr ""
+__EXPECTED__
+
+write_po_ok(<<'__EXAMPLE__'                => <<'__EXPECTED__', "q with multilines with args");
+_(q{example %1
+with multilines
+},20);
+__EXAMPLE__
+#: :1
+#. (20)
+msgid ""
+"example %1\n"
+"with multilines\n"
+msgstr ""
+__EXPECTED__
+
+write_po_ok(<<'__EXAMPLE__'                => <<'__EXPECTED__', "null terminator with multilines with args (heredoc)");
+_(<<"", 15)
+example %1
+with multilines
+
+__EXAMPLE__
+#: :1
+#. (15)
+msgid ""
+"example %1\n"
+"with multilines\n"
+msgstr ""
+__EXPECTED__
+
+write_po_ok(<<'__EXAMPLE__'                => <<'__EXPECTED__', "null terminator with end after the heredoc with args (heredoc)");
+_(<<"", 10)
+example %1
+
+__EXAMPLE__
+#: :1
+#. (10)
+msgid "example %1\n"
+msgstr ""
+__EXPECTED__
+
+write_po_ok(<<'__EXAMPLE__'                => <<'__EXPECTED__', "two _() calls (heredoc)");
+_(<<"", 10)
+example1 %1
+
+_(<<"", 5)
+example2 %1
+
+__EXAMPLE__
+#: :1
+#. (10)
+msgid "example1 %1\n"
+msgstr ""
+
+#: :4
+#. (5)
+msgid "example2 %1\n"
+msgstr ""
+__EXPECTED__
 
 sub extract_ok {
     my ($text, $expected, $info, $verbatim) = @_;
@@ -67,3 +182,28 @@
     $Ext->clear;
 }
 
+sub write_po_ok {
+    my ($text, $expected, $info, $verbatim) = @_;
+    my $po_file = 't/5-extract.po';
+
+    # create .po
+    $Ext->extract('' => $text);
+    $Ext->compile($verbatim);
+    $Ext->write_po($po_file);
+
+    # read .po
+    open(my $po_handle,'<',$po_file) or die("Cannot open $po_file: $!");
+    local $/ = undef;
+    my $result = <$po_handle>;
+    close($po_handle);
+    unlink($po_file) or die("Cannot unlink $po_file: $!");
+
+    # cut the header from result
+    my $start_expected = length($Ext->header);
+    $start_expected++  if( $start_expected < length($result) );
+
+    # check result vs expected
+    is(substr($result, $start_expected), $expected, $info );
+    $Ext->clear;
+}
+




More information about the Pkg-perl-cvs-commits mailing list