[Bps-public-commit] r16990 - in Locale-Maketext-Lexicon/trunk: lib/Locale/Maketext lib/Locale/Maketext/Extract/Plugin

clint at bestpractical.com clint at bestpractical.com
Sat Nov 22 14:41:18 EST 2008


Author: clint
Date: Sat Nov 22 14:41:18 2008
New Revision: 16990

Added:
   Locale-Maketext-Lexicon/trunk/t/9-bug-import-for-subclasses.t
   Locale-Maketext-Lexicon/trunk/t/91-pod_test.t
Removed:
   Locale-Maketext-Lexicon/trunk/t/99-bug-import-for-subclasses.t
Modified:
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract.pm
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TT2.pm
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TextTemplate.pm
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/YAML.pm
   Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon.pm
   Locale-Maketext-Lexicon/trunk/t/5-extract.t

Log:
More changes for version 0.73

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 14:41:18 2008
@@ -1,5 +1,5 @@
 package Locale::Maketext::Extract;
-$Locale::Maketext::Extract::VERSION = '0.30';
+$Locale::Maketext::Extract::VERSION = '0.31';
 
 use strict;
 

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TT2.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TT2.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TT2.pm	Sat Nov 22 14:41:18 2008
@@ -135,6 +135,8 @@
     return ( qw( tt tt2 html ), qr/\.tt2?\./ );
 }
 
+my %Escapes = map { ( "\\$_" => eval("qq(\\$_)") ) } qw(t n r f b a e);
+
 #===================================
 sub extract {
 #===================================
@@ -158,8 +160,16 @@
         || die $parser->error;
 
     foreach my $entry ( @{ $parser->{extracted} } ) {
-        $entry->[2]=~s/^\((.*)\)$/$1/; # Remove () from vars
-        $self->add_entry( @$entry);
+        $entry->[2] =~ s/^\((.*)\)$/$1/s;    # Remove () from vars
+        $_ =~ s/\\'/'/gs                     # Unescape \'
+            for @{$entry}[ 0, 2 ];
+        $entry->[2] =~ s/\\(?!")/\\\\/gs;    # Escape all \ not followed by "
+                                             # Escape argument lists correctly
+        while ( my ( $char, $esc ) = each %Escapes ) {
+            $entry->[2] =~ s/$esc/$char/g;
+        }
+
+        $self->add_entry(@$entry);
     }
 }
 
@@ -235,6 +245,7 @@
 sub textblock {
 #===================================
     my ( $class, $text ) = @_;
+    $text =~ s/([\\'])/\\$1/g;
     return "'$text'";
 }
 
@@ -272,6 +283,7 @@
         {
             my $string = shift @{ $ident->[1] };
             strip_quotes($string);
+            $string =~ s/\\\\/\\/g;
             my $args = join_args( $ident->[1] );
             push @{ $PARSER->{extracted} },
                 [ $string, ${ $PARSER->{LINE} }, $args ];
@@ -284,16 +296,17 @@
 sub text {
 #===================================
     my ( $class, $text ) = @_;
+    $text =~ s/\\/\\\\/g;
     return "'$text'";
 }
 
 #===================================
 sub quoted {
 #===================================
-    my ($class, $items) = @_;
+    my ( $class, $items ) = @_;
     return '' unless @$items;
-    return ($items->[0]) if scalar @$items == 1;
-    return '(' . join(' _ ', @$items) . ')';
+    return ( $items->[0] ) if scalar @$items == 1;
+    return '(' . join( ' _ ', @$items ) . ')';
 }
 
 #===================================
@@ -323,6 +336,7 @@
         unless $name eq "'l'"
             or $name eq "'loc'";
     if ( strip_quotes($block) ) {
+        $block =~ s/\\\\/\\/g;
         $args = join_args( $class->args($args) );
 
         # NOTE: line number is at end of block, and can be a range
@@ -351,7 +365,15 @@
 #===================================
     my $args = shift;
     return '' unless $args && @$args;
-    return '(' . join( ', ', @$args ) . ')';
+    my @new_args = (@$args);
+    for (@new_args) {
+        s/\\\\/\\/g;
+        if ( strip_quotes($_) ) {
+            s/"/\\"/g;
+            $_ = qq{"$_"};
+        }
+    }
+    return '(' . join( ', ', @new_args ) . ')';
 }
 
 =head1 ACKNOWLEDGEMENTS

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TextTemplate.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TextTemplate.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/TextTemplate.pm	Sat Nov 22 14:41:18 2008
@@ -4,7 +4,7 @@
 use base qw(Locale::Maketext::Extract::Plugin::Base);
 use vars qw($VERSION);
 
-$VERSION = '0.30';
+$VERSION = '0.31';
 
 =head1 NAME
 
@@ -58,8 +58,8 @@
         require Lingua::EN::Sentence;
 
         {
-            package MyParser;
-            @MyParser::ISA = 'HTML::Parser';
+            package Locale::Maketext::Extract::Plugin::TextTemplate::Parser;
+            our @ISA = 'HTML::Parser';
             *{'text'} = sub {
                 my ($self, $str, $is_cdata) = @_;
                 my $sentences = Lingua::EN::Sentence::get_sentences($str) or return;
@@ -68,7 +68,7 @@
             };
         }
 
-        my $p = MyParser->new;
+        my $p = Locale::Maketext::Extract::Plugin::TextTemplate::Parser->new;
         while (m/\G((.*?)^(?:START|END)[A-Z]+$)/smg) {
             my ($str) = ($2);
             $line += ( () = ($1 =~ /\n/g) ); # cryptocontext!

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/YAML.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/YAML.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Extract/Plugin/YAML.pm	Sat Nov 22 14:41:18 2008
@@ -38,6 +38,8 @@
 
 =back
 
+You cannot use block or folded strings with this plugin.
+
 =head1 KNOWN FILE TYPES
 
 =over 4

Modified: Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon.pm
==============================================================================
--- Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon.pm	(original)
+++ Locale-Maketext-Lexicon/trunk/lib/Locale/Maketext/Lexicon.pm	Sat Nov 22 14:41:18 2008
@@ -1,5 +1,5 @@
 package Locale::Maketext::Lexicon;
-$Locale::Maketext::Lexicon::VERSION = '0.71';
+$Locale::Maketext::Lexicon::VERSION = '0.73';
 
 use 5.004;
 use strict;

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 14:41:18 2008
@@ -1,7 +1,7 @@
 #! /usr/bin/perl -w
 use lib '../lib';
 use strict;
-use Test::More tests => 76;
+use Test::More tests => 95;
 
 use_ok('Locale::Maketext::Extract');
 my $Ext = Locale::Maketext::Extract->new();
@@ -63,7 +63,7 @@
 
 
 #### BEGIN TT TESTS ############
-SKIP: { skip('Template.pm unavailable', 27) unless eval { require Template };
+SKIP: { skip('Template.pm unavailable', 46) unless eval { require Template };
 
 extract_ok(<<'__EXAMPLE__'                 => 'foo bar baz', 'trim the string (tt)');
 [% |loc -%]
@@ -88,7 +88,7 @@
 
 write_po_ok(q([% l('string','arg') %])     => <<'__EXAMPLE__', 'TT l function - literal arg');
 #: :1
-#. ('arg')
+#. ("arg")
 msgid "string"
 msgstr ""
 __EXAMPLE__
@@ -103,7 +103,7 @@
 
 write_po_ok(q([% 'string' | l('arg')  %])  => <<'__EXAMPLE__', 'TT l inline filter - literal arg');
 #: :1
-#. ('arg')
+#. ("arg")
 msgid "string"
 msgstr ""
 __EXAMPLE__
@@ -119,6 +119,7 @@
 
 SKIP: {
     skip "Can't handle directive embedded in text blocks",1;
+
     write_po_ok(q([% |l %] string [% var %][% END %])    => '', 'TT l block filter - embedded directive');
 }
 
@@ -130,7 +131,7 @@
 
 write_po_ok(q([% |l('arg') %]string[% END %]) => <<'__EXAMPLE__', 'TT l block filter - literal arg');
 #: :1
-#. ('arg')
+#. ("arg")
 msgid "string"
 msgstr ""
 __EXAMPLE__
@@ -164,7 +165,7 @@
 
 write_po_ok(q([% 'string' | loc('arg')  %])  => <<'__EXAMPLE__', 'TT loc inline filter - literal arg');
 #: :1
-#. ('arg')
+#. ("arg")
 msgid "string"
 msgstr ""
 __EXAMPLE__
@@ -203,6 +204,196 @@
 extract_ok(q([% l("embedded \${string}") %]) => 'embedded ${string}', "TT embedded string 2");
 extract_ok(q([% l('embedded ${string}') %]) => 'embedded ${string}',  "TT embedded string 3");
 
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 1');
+[% l('my \ string', 'my \ string') %]
+[% l('my \\ string', 'my \\ string') %]
+[% l("my \\ string", "my \\ string") %]
+__TT__
+#: :1 :2 :3
+#. ("my \\ string")
+msgid "my \\ string"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 2');
+[% l('my str\'ing','my str\'ing') %]
+__TT__
+#: :1
+#. ("my str'ing")
+msgid "my str'ing"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 3');
+[% l('my string"','my string"') %]
+__TT__
+#: :1
+#. ("my string\"")
+msgid "my string\""
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 4');
+[% l("my string'","my string'") %]
+__TT__
+#: :1
+#. ("my string'")
+msgid "my string'"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 5');
+[% l("my \nstring","my \nstring") %]
+__TT__
+#: :1
+#. ("my \nstring")
+msgid ""
+"my \n"
+"string"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 6');
+[% l('my \nstring','my \nstring') %]
+__TT__
+#: :1
+#. ("my \\nstring")
+msgid "my \\nstring"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 7');
+[% 'my \ string'  | l('my \ string') %]
+[% 'my \\ string' | l('my \\ string') %]
+[% "my \\ string" | l("my \\ string") %]
+__TT__
+#: :1 :2 :3
+#. ("my \\ string")
+msgid "my \\ string"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 8');
+[% 'my str\'ing' | l('my str\'ing') %]
+__TT__
+#: :1
+#. ("my str'ing")
+msgid "my str'ing"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 9');
+[% 'my string"' | l('my string"') %]
+__TT__
+#: :1
+#. ("my string\"")
+msgid "my string\""
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 10');
+[% "my string'" |l("my string'") %]
+__TT__
+#: :1
+#. ("my string'")
+msgid "my string'"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 11');
+[% "my \nstring" |l("my \nstring") %]
+__TT__
+#: :0-1
+#. ("my \nstring")
+msgid ""
+"my \n"
+"string"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 12');
+[% 'my \nstring' |l('my \nstring') %]
+__TT__
+#: :1
+#. ("my \\nstring")
+msgid "my \\nstring"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 13');
+[% | l('my \ string') %]my \ string[% END %]
+[% | l('my \\ string') %]my \\ string[% END %]
+__TT__
+#: :1
+#. ("my \\ string")
+msgid "my \\ string"
+msgstr ""
+
+#: :2
+#. ("my \\ string")
+msgid "my \\\\ string"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 14');
+[% | l('my str\'ing') %]my str'ing[% END %]
+__TT__
+#: :1
+#. ("my str'ing")
+msgid "my str'ing"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 15');
+[% | l('my str\'ing') %]my str\'ing[% END %]
+__TT__
+#: :1
+#. ("my str'ing")
+msgid "my str\\'ing"
+msgstr ""
+__EXAMPLE__
+
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 16');
+[% | l("my str\"ing") %]my str"ing[% END %]
+__TT__
+#: :1
+#. ("my str\"ing")
+msgid "my str\"ing"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 17');
+[% | l("my str\"ing") %]my str\"ing[% END %]
+__TT__
+#: :1
+#. ("my str\"ing")
+msgid "my str\\\"ing"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 18');
+[% |l("my \nstring") %]my
+string[% END %]
+__TT__
+#: :1-2
+#. ("my \nstring")
+msgid ""
+"my\n"
+"string"
+msgstr ""
+__EXAMPLE__
+
+write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT quoted - 19');
+[% |l('my \nstring') %]my \nstring[% END %]
+__TT__
+#: :1
+#. ("my \\nstring")
+msgid "my \\nstring"
+msgstr ""
+__EXAMPLE__
+
+
 write_po_ok(<<'__TT__'  => <<'__EXAMPLE__', 'TT key values');
 [% l('string', key1=>'value',key2=>value, key3 => value.method) %]
 __TT__
@@ -216,7 +407,7 @@
 [% l('string',b.method.$var(arg),c('arg').method.5) %]
 __TT__
 #: :1
-#. (b.method.$var(arg), c('arg').method.5)
+#. (b.method.$var(arg), c("arg").method.5)
 msgid "string"
 msgstr ""
 __EXAMPLE__
@@ -225,7 +416,7 @@
 }
 
 #### BEGIN YAML TESTS ############
-SKIP: { skip('YAML.pm unavailable', 27) unless eval { require YAML };
+SKIP: { skip('YAML.pm unavailable', 18) unless eval { require YAML };
 
 extract_ok(qq(key: _"string"\n)               => "string",       "YAML double quotes");
 extract_ok(qq(key: _'string'\n)               => "string",       "YAML single quotes");

Added: Locale-Maketext-Lexicon/trunk/t/9-bug-import-for-subclasses.t
==============================================================================
--- (empty file)
+++ Locale-Maketext-Lexicon/trunk/t/9-bug-import-for-subclasses.t	Sat Nov 22 14:41:18 2008
@@ -0,0 +1,48 @@
+#!/usr/bin/perl -w
+use strict;
+use Test::More tests => 4;
+
+package Hello::I18N;
+use base qw/Locale::Maketext/;
+
+package Hello::I18N::zh_tw;
+use base qw/Hello::I18N/;
+use Locale::Maketext::Lexicon ( Gettext => 't/messages.mo', );
+
+package Hello::I18N::bzh_bzh;
+use base qw/Hello::I18N/;
+use Locale::Maketext::Lexicon ( Gettext => \*::DATA, _use_fuzzy => 1);
+
+package main;
+
+ok(my $lh = Hello::I18N->get_handle('zh-tw'), 'got handle');
+
+is(
+	$lh->maketext('This is a test'),
+	'這是測試',
+    'translated'
+);
+
+ok($lh = Hello::I18N->get_handle('bzh_BZH'), 'Gettext - get_handle on DATA again');
+is(
+    eval { $lh->maketext("See you another time!") },
+    "D'ur wech all !",
+    'Gettext - fuzzy recognized: _use_fuzzy has been set'
+);
+
+__DATA__
+msgid ""
+msgstr ""
+"Project-Id-Version: Test App 0.01\n"
+"POT-Creation-Date: 2006-06-13 11:36+0800\n"
+"PO-Revision-Date: 2006-06-13 02:00+0800\n"
+"Last-Translator: <yannk at cpan.org>\n"
+"Language-Team: German <yannk at cpan.org>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=ISO-8859-1\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: Hello.pm:16
+#, big, furry, fuzzy
+msgid "See you another time!"
+msgstr "D'ur wech all !"

Added: Locale-Maketext-Lexicon/trunk/t/91-pod_test.t
==============================================================================
--- (empty file)
+++ Locale-Maketext-Lexicon/trunk/t/91-pod_test.t	Sat Nov 22 14:41:18 2008
@@ -0,0 +1,4 @@
+use Test::More;
+eval "use Test::Pod 1.00";
+plan skip_all => "Test::Pod 1.00 required for testing POD" if $@;
+all_pod_files_ok();



More information about the Bps-public-commit mailing list