Subject: | concat in loc() works now and TT can now use [% FILTER loc %] |
now it is possible to concat strings in loc() and in TT you can use [%
FILTER loc %]
Subject: | tests-for-new-patch-for-concat-and-tt-FILTER.patch |
--- Locale-Maketext-Lexicon-0.68/t/5-extract.t.orig 2008-09-07 02:13:04.000000000 +0200
+++ Locale-Maketext-Lexicon-0.68/t/5-extract.t 2008-09-07 03:23:01.000000000 +0200
@@ -1,7 +1,7 @@
#! /usr/bin/perl -w
use lib '../lib';
use strict;
-use Test::More tests => 43;
+use Test::More tests => 47;
use_ok('Locale::Maketext::Extract');
my $Ext = Locale::Maketext::Extract->new;
@@ -61,6 +61,12 @@
extract_ok(q(_("","car")) => '', 'ignore empty string');
extract_ok(q(_("0")) => '', 'ignore zero');
+extract_ok(<<'__EXAMPLE__' => 'foo bar baz', 'use FILTER (tt)');
+[% FILTER l -%]
+foo bar baz
+[%- END %]
+__EXAMPLE__
+
extract_ok(<<'__EXAMPLE__' => 'foo bar baz', 'trim the string (tt)');
[% |loc -%]
foo bar baz
@@ -173,6 +179,50 @@
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) = @_;
Subject: | patch-for-concat-and-tt-FILTER.patch |
--- Locale-Maketext-Lexicon-0.68/lib/Locale/Maketext/Extract.pm.orig 2008-09-07 02:12:33.000000000 +0200
+++ Locale-Maketext-Lexicon-0.68/lib/Locale/Maketext/Extract.pm 2008-09-07 03:22:12.000000000 +0200
@@ -255,7 +255,7 @@
# Template Toolkit
$line = 1; pos($_) = 0;
- while (m!\G(.*?\[%-?\s*\|l(?:oc)?(.*?)\s*(-?)%\](.*?)\[%(-?)\s*END\s*-?%\])!sg) {
+ while (m!\G(.*?\[%-?\s*(?:\|\s*|FILTER\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*\(//;
@@ -305,7 +305,7 @@
}
# Perl code:
- my ($state,$str,$vars,$quo,$heredoc)=(0);
+ my ($state,$line_offset,$str,$str_part,$vars,$quo,$heredoc)=(0,0);
pos($_) = 0;
my $orig = 1 + (() = ((my $__ = $_) =~ /\n/g));
@@ -322,28 +322,45 @@
$state == BEG && 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 heredoc and go back to current position
@@ -360,7 +377,7 @@
$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 };
+ $state == HERE && m/^.*\r?\n/gc && s/\G(.*?\r?\n)$heredoc(\r?\n)//s && do { $state = PAR; $str_part .= $1; $line_offset++; redo };
# end ()
#
@@ -368,15 +385,9 @@
$state == PAR && m/^\s*[\)]/gc && do {
$state = NUL;
$vars =~ s/[\n\r]//g if ($vars);
- 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
- push @{$entries->{$str}}, [ $file, $line - (() = $str =~ /\n/g) - defined($heredoc), $vars] if ($str);
+ push @{$entries->{$str}}, [ $file, $line - (() = $str =~ /\n/g) - $line_offset, $vars] if ($str);
undef $str; undef $vars; undef $heredoc;
+ $line_offset = 0;
redo;
};