[Rt-commit] r4935 - in Locale-Maketext-Lexicon: .
lib/Locale/Maketext
autrijus at bestpractical.com
autrijus at bestpractical.com
Sun Apr 2 06:46:25 EDT 2006
Author: autrijus
Date: Sun Apr 2 06:46:23 2006
New Revision: 4935
Modified:
Locale-Maketext-Lexicon/Changes
Locale-Maketext-Lexicon/lib/Locale/Maketext/Lexicon.pm
Locale-Maketext-Lexicon/t/messages.mo
Log:
* _style support
Modified: Locale-Maketext-Lexicon/Changes
==============================================================================
--- Locale-Maketext-Lexicon/Changes (original)
+++ Locale-Maketext-Lexicon/Changes Sun Apr 2 06:46:23 2006
@@ -4,6 +4,10 @@
now turns on _AUTO fallback handling for all language handles.
Requested by: Jesse Vincent
+* Locale::Maketext::Lexicon: Specifying the new "_style => 'gettext'"
+ option makes "%1" and "%quant(%1)" to be used for interpolation,
+ instead of "[_1]" and "[quant,_1]".
+
[Changes for 0.55 - 2006-03-22]
* Locale::Maketext::Extract: Fix a long-standing bug that caused
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 Sun Apr 2 06:46:23 2006
@@ -21,8 +21,12 @@
use base 'Locale::Maketext';
use Locale::Maketext::Lexicon {
'*' => [Gettext => '/usr/local/share/locale/*/LC_MESSAGES/hello.mo'],
- _decode => 1, # decode lexicon entries into utf8-strings
- _auto => 1, # fallback when a key is missing from lexicons
+ ### Uncomment to decode lexicon entries into Unicode strings
+ # _decode => 1,
+ ### Uncomment to fallback when a key is missing from lexicons
+ # _auto => 1,
+ ### Uncomment to use %1 / %quant(%1) instead of [_1] / [quant, _1]
+ # _style => 'gettext',
};
Explicitly specify languages, during compile- or run-time:
@@ -312,11 +316,34 @@
};
}
- push(@{"$export\::ISA"}, scalar caller) if length $lang;
+ length $lang or next;
+
+ push(@{"$export\::ISA"}, scalar caller);
+
+ if (my $style = option('style')) {
+ my $cref = $class->can(lc("_style_$style"))->( $class, $export->can('maketext') )
+ or die "Unknown style: $style";
+ *{"$export\::maketext"} = $cref;
+ }
}
}
}
+sub _style_gettext {
+ my ($self, $orig) = @_;
+
+ sub {
+ my $lh = shift;
+ my $str = shift;
+ print STDERR "$str\n";
+ $str =~ s/[\~\[\]]/~$&/g;
+ $str =~ s{(^|[^%\\])%([A-Za-z#*]\w*)\(([^\)]*)\)}
+ {"$1\[$2,"._unescape($3)."]"}eg;
+ $str =~ s/(^|[^%\\])%(\d+|\*)/$1\[_$2]/g;
+ return $orig->($lh, $str, @_);
+ }
+}
+
sub TIEHASH {
my ($class, $args) = @_;
return bless($args, $class);
Modified: Locale-Maketext-Lexicon/t/messages.mo
==============================================================================
Binary files. No diff available.
More information about the Rt-commit
mailing list