[Rt-commit] r5027 - in Locale-Maketext-Lexicon: .
lib/Locale/Maketext/Extract lib/Locale/Maketext/Lexicon
autrijus at bestpractical.com
autrijus at bestpractical.com
Wed Apr 12 20:50:00 EDT 2006
Author: autrijus
Date: Wed Apr 12 20:49:57 2006
New Revision: 5027
Modified:
Locale-Maketext-Lexicon/Changes
Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm
Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract/Run.pm
Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon.pm
Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Gettext.pm
Log:
* This be 0.58.
* Locale::Maketext::Extract: Direct calls to ->write_po now
escapes the msg strings by default (reverting to <=0.54
behaviour), but calls via xgettext.pl (and ::Extract::Run)
now always specify the "verbatim" flag to ->write_po, so
users of extraction tools are still free from double escaping.
Requested by: Thierry Vignaud
* Locale::Maketext::Extract: Allow the "# loc" marker at the
end of a statement:
say "foo"; # loc
previously it only worked on closing brackets and commas.
* Locale::Maketext::Lexicon: The "gettext" style no longer parses
"%0" as a variable. Also allows spaces between function arguments:
%quant(%1, %2)
Modified: Locale-Maketext-Lexicon/Changes
==============================================================================
--- Locale-Maketext-Lexicon/Changes (original)
+++ Locale-Maketext-Lexicon/Changes Wed Apr 12 20:49:57 2006
@@ -1,3 +1,21 @@
+[Changes for 0.58 - 2006-04-13]
+
+* Locale::Maketext::Extract: Direct calls to ->write_po now
+ escapes the msg strings by default (reverting to <=0.54
+ behaviour), but calls via xgettext.pl (and ::Extract::Run)
+ now always specify the "verbatim" flag to ->write_po, so
+ users of extraction tools are still free from double escaping.
+ Requested by: Thierry Vignaud
+
+* Locale::Maketext::Extract: Allow the "# loc" marker at the
+ end of a statement:
+ say "foo"; # loc
+ previously it only worked on closing brackets and commas.
+
+* Locale::Maketext::Lexicon: The "gettext" style no longer parses
+ "%0" as a variable. Also allows spaces between function arguments:
+ %quant(%1, %2)
+
[Changes for 0.57 - 2006-04-11]
* Locale::Maketext::Locale: The "_style => 'gettext'" option was
Modified: Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm
==============================================================================
--- Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm (original)
+++ Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract.pm Wed Apr 12 20:49:57 2006
@@ -1,5 +1,5 @@
package Locale::Maketext::Extract;
-$Locale::Maketext::Extract::VERSION = '0.11';
+$Locale::Maketext::Extract::VERSION = '0.12';
use strict;
@@ -99,8 +99,7 @@
=head2 PO File manipulation
- read_po
- write_po
+=head3 method read_po ($file, $verbatim?)
=cut
@@ -127,8 +126,12 @@
close LEXICON;
}
+=head3 method write_po ($file, $add_format?, $verbatim?)
+
+=cut
+
sub write_po {
- my ($self, $file, $add_format) = @_;
+ my ($self, $file, $add_format, $verbatim) = @_;
local *LEXICON;
open LEXICON, ">$file" or die "Can't write to $file$!\n";
@@ -141,7 +144,7 @@
print LEXICON $self->msg_positions($msgid);
print LEXICON $self->msg_variables($msgid);
print LEXICON $self->msg_format($msgid) if $add_format;
- print LEXICON $self->msg_out($msgid);
+ print LEXICON $self->msg_out($msgid, $verbatim);
}
}
@@ -221,7 +224,7 @@
# Comment-based mark: "..." # loc
$line = 1; pos($_) = 0;
- while (m/\G(.*?($quoted)[\}\)\],]*\s*\#\s*loc\s*$)/smog) {
+ while (m/\G(.*?($quoted)[\}\)\],;]*\s*\#\s*loc\s*$)/smog) {
my $str = substr($2, 1, -1);
$line += ( () = ( $1 =~ /\n/g ) ); # cryptocontext!
$str =~ s/\\(["'])/$1/g;
@@ -230,7 +233,7 @@
# Comment-based pair mark: "..." => "..." # loc_pair
$line = 1; pos($_) = 0;
- while (m/\G(.*?(\w+)\s*=>\s*($quoted)[\}\)\],]*\s*\#\s*loc_pair\s*$)/smg) {
+ while (m/\G(.*?(\w+)\s*=>\s*($quoted)[\}\)\],;]*\s*\#\s*loc_pair\s*$)/smg) {
my $key = $2;
my $val = substr($3, 1, -1);
$line += ( () = ( $1 =~ /\n/g ) ); # cryptocontext!
@@ -378,15 +381,21 @@
sub msg_format {
my ($self, $msgid) = @_;
- return "#, perl-maketext-format\n" if $msgid =~ /%(?:\d|\w+\([^\)]*\))/;
+ return "#, perl-maketext-format\n" if $msgid =~ /%(?:[1-9]\d*|\w+\([^\)]*\))/;
return '';
}
sub msg_out {
- my ($self, $msgid) = @_;
+ my ($self, $msgid, $verbatim) = @_;
+ my $msgstr = $self->msgstr($msgid);
+
+ if (!$verbatim) {
+ $msgid =~ s/(?=[\\"])/\\/g;
+ $msgstr =~ s/(?=[\\"])/\\/g;
+ }
return "msgid " . _format($msgid) .
- "msgstr " . _format($self->msgstr($msgid));
+ "msgstr " . _format($msgstr);
}
=head2 Internal utilities
@@ -431,7 +440,7 @@
}
return $text if $verbatim;
- $text =~ s/((?<!~)(?:~~)*)\[_(\d+)\]/$1%$2/g;
+ $text =~ s/((?<!~)(?:~~)*)\[_([1-9]\d*)\]/$1%$2/g;
$text =~ s/((?<!~)(?:~~)*)\[([A-Za-z#*]\w*),([^\]]+)\]/$1%$2("""$3""")/g;
$text = join('', map {
/^""".*"""$/ ? _escape(substr($_, 3, -3)) : $_
@@ -443,7 +452,7 @@
sub _escape {
my $text = shift;
- $text =~ s/\b_(\d+)/%$1/g;
+ $text =~ s/\b_([1-9]\d*)/%$1/g;
return $text;
}
@@ -482,7 +491,7 @@
=head1 COPYRIGHT
-Copyright 2003, 2004 by Audrey Tang E<lt>audreyt at audreyt.orgE<gt>.
+Copyright 2003, 2004, 2005, 2006 by Audrey Tang E<lt>audreyt at audreyt.orgE<gt>.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
Modified: Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract/Run.pm
==============================================================================
--- Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract/Run.pm (original)
+++ Locale-Maketext-Lexicon/lib/Locale/Maketext/Extract/Run.pm Wed Apr 12 20:49:57 2006
@@ -71,7 +71,9 @@
$Ext->compile($opts{u}) or next;
chdir $dir;
- $Ext->write_po($po, $opts{g});
+
+ use constant ALWAYS_VERBATIM => 1;
+ $Ext->write_po($po, $opts{g}, ALWAYS_VERBATIM);
chdir $cwd;
}
}
Modified: Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon.pm
==============================================================================
--- Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon.pm (original)
+++ Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon.pm Wed Apr 12 20:49:57 2006
@@ -1,5 +1,5 @@
package Locale::Maketext::Lexicon;
-$Locale::Maketext::Lexicon::VERSION = '0.57';
+$Locale::Maketext::Lexicon::VERSION = '0.58';
use strict;
@@ -9,8 +9,8 @@
=head1 VERSION
-This document describes version 0.57 of Locale::Maketext::Lexicon,
-released April 11, 2006.
+This document describes version 0.58 of Locale::Maketext::Lexicon,
+released April 13, 2006.
=head1 SYNOPSIS
@@ -339,30 +339,15 @@
sub _style_gettext {
my ($self, $orig) = @_;
+ require Locale::Maketext::Lexicon::Gettext;
+
sub {
my $lh = shift;
my $str = shift;
- $str =~ s{([\~\[\]])}{~$1}g;
- $str =~ s{ ([%\\]%) # 1 - escaped sequence
- | %
- (?:
- ([A-Za-z#*]\w*) # 2 - function call
- \(([^\)]*)\) # 3 - arguments
- |
- (\d+|\*) # 4 - variable
- )
- }
- {$1 ? $1 : $2 ? "\[$2,"._unescape($3)."]" : "[_$4]"}egx;
- return $orig->($lh, $str, @_);
+ return $orig->($lh, Locale::Maketext::Lexicon::Gettext::_gettext_to_maketext($str), @_);
}
}
-sub _unescape {
- my $str = shift;
- $str =~ s/(^|,)%(\d+|\*)(,|$)/$1_$2$3/g;
- return $str;
-}
-
sub TIEHASH {
my ($class, $args) = @_;
return bless($args, $class);
Modified: Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Gettext.pm
==============================================================================
--- Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Gettext.pm (original)
+++ Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon/Gettext.pm Wed Apr 12 20:49:57 2006
@@ -193,19 +193,32 @@
: Encode::encode($OutputEncoding, $str)
}
- $str =~ s/([~\[\]])/~$1/g;
- $str =~ s/(?<![%\\])%([A-Za-z#*]\w*)\(([^\)]*)\)/[$1,~~~$2~~~]/g;
- $str = join('', map {
- /^~~~.*~~~$/ ? unescape(substr($_, 3, -3)) : $_
- } split(/(~~~.*?~~~)/, $str));
- $str =~ s/(?<![%\\])%(\d+|\*)/\[_$1]/g;
+ return _gettext_to_maketext($str);
+}
- return $str;
+sub _gettext_to_maketext {
+ my $str = shift;
+ $str =~ s{([\~\[\]])}{~$1}g;
+ $str =~ s{
+ ([%\\]%) # 1 - escaped sequence
+ |
+ % (?:
+ ([A-Za-z#*]\w*) # 2 - function call
+ \(([^\)]*)\) # 3 - arguments
+ |
+ ([1-9]\d*|\*) # 4 - variable
+ )
+ }{
+ $1 ? $1
+ : $2 ? "\[$2,"._unescape($3)."]"
+ : "[_$4]"
+ }egx;
+ $str;
}
-sub unescape {
+sub _unescape {
join(',', map {
- /^%(?:\d+|\*)$/ ? ("_" . substr($_, 1)) : $_
+ /\A(\s*)%([1-9]\d*|\*)(\s*)\z/ ? "$1_$2$3" : $_
} split(/,/, $_[0]));
}
More information about the Rt-commit
mailing list