diff options
author | Chris Williams <chris@bingosnet.co.uk> | 2009-09-11 12:14:21 +0100 |
---|---|---|
committer | Chris Williams <chris@bingosnet.co.uk> | 2009-09-11 12:14:21 +0100 |
commit | ffd1a11dbdc72439ae1ddf3a36ee639db4a76f82 (patch) | |
tree | b209fbb0fab90d4f1d10b0e2f19ed7beb4026bac | |
parent | a94275b4c55a8372524a9e776ddd35f2e57be56d (diff) | |
download | perl-ffd1a11dbdc72439ae1ddf3a36ee639db4a76f82.tar.gz |
Updated Locale-Maketext-Simple to CPAN version 0.21
-rw-r--r-- | MANIFEST | 7 | ||||
-rw-r--r-- | ext/Locale-Maketext-Simple/lib/Locale/Maketext/Simple.pm | 15 | ||||
-rwxr-xr-x[-rw-r--r--] | ext/Locale-Maketext-Simple/t/1-basic.t | 0 | ||||
-rwxr-xr-x | ext/Locale-Maketext-Simple/t/2-load_po_without_i_default.t | 30 | ||||
-rwxr-xr-x | ext/Locale-Maketext-Simple/t/3-load_po_with_i_default.t | 31 | ||||
-rw-r--r-- | ext/Locale-Maketext-Simple/t/po_with_i_default/en.po | 30 | ||||
-rw-r--r-- | ext/Locale-Maketext-Simple/t/po_with_i_default/fr.po | 30 | ||||
-rw-r--r-- | ext/Locale-Maketext-Simple/t/po_with_i_default/i_default.po | 30 | ||||
-rw-r--r-- | ext/Locale-Maketext-Simple/t/po_without_i_default/en.po | 30 | ||||
-rw-r--r-- | ext/Locale-Maketext-Simple/t/po_without_i_default/fr.po | 30 |
10 files changed, 227 insertions, 6 deletions
@@ -1613,6 +1613,13 @@ ext/List-Util/XS.pp List::Util ext/Locale-Maketext-Simple/lib/Locale/Maketext/Simple.pm Locale::Simple ext/Locale-Maketext-Simple/t/0-signature.t Locale::Simple tests ext/Locale-Maketext-Simple/t/1-basic.t Locale::Simple tests +ext/Locale-Maketext-Simple/t/2-load_po_without_i_default.t Locale::Simple tests +ext/Locale-Maketext-Simple/t/3-load_po_with_i_default.t Locale::Simple tests +ext/Locale-Maketext-Simple/t/po_with_i_default/en.po Locale::Simple tests +ext/Locale-Maketext-Simple/t/po_with_i_default/fr.po Locale::Simple tests +ext/Locale-Maketext-Simple/t/po_with_i_default/i_default.po Locale::Simple tests +ext/Locale-Maketext-Simple/t/po_without_i_default/en.po Locale::Simple tests +ext/Locale-Maketext-Simple/t/po_without_i_default/fr.po Locale::Simple tests ext/Log-Message/lib/Log/Message/Config.pm Log::Message ext/Log-Message/lib/Log/Message/Handlers.pm Log::Message ext/Log-Message/lib/Log/Message/Item.pm Log::Message diff --git a/ext/Locale-Maketext-Simple/lib/Locale/Maketext/Simple.pm b/ext/Locale-Maketext-Simple/lib/Locale/Maketext/Simple.pm index ddc1c65645..30760f3c26 100644 --- a/ext/Locale-Maketext-Simple/lib/Locale/Maketext/Simple.pm +++ b/ext/Locale-Maketext-Simple/lib/Locale/Maketext/Simple.pm @@ -1,8 +1,8 @@ package Locale::Maketext::Simple; -$Locale::Maketext::Simple::VERSION = '0.18'; +$Locale::Maketext::Simple::VERSION = '0.21'; use strict; -use 5.004; +use 5.005; =head1 NAME @@ -46,6 +46,10 @@ This module is a simple wrapper around B<Locale::Maketext::Lexicon>, designed to alleviate the need of creating I<Language Classes> for module authors. +The language used is chosen from the loc_lang call. If a lookup is not +possible, the i-default language will be used. If the lookup is not in the +i-default language, then the key will be returned. + If B<Locale::Maketext::Lexicon> is not present, it implements a minimal localization function by simply interpolating C<[_1]> with the first argument, C<[_2]> with the second, etc. Interpolated @@ -146,19 +150,19 @@ sub load_loc { eval " package $pkg; use base 'Locale::Maketext'; - %${pkg}::Lexicon = ( '_AUTO' => 1 ); Locale::Maketext::Lexicon->import({ 'i-default' => [ 'Auto' ], '*' => [ Gettext => \$pattern ], _decode => \$decode, _encoding => \$encoding, }); + *${pkg}::Lexicon = \\%${pkg}::i_default::Lexicon; *tense = sub { \$_[1] . ((\$_[2] eq 'present') ? 'ing' : 'ed') } unless defined &tense; 1; " or die $@; - + my $lh = eval { $pkg->get_handle } or return; my $style = lc($args{Style}); if ($style eq 'maketext') { @@ -193,7 +197,6 @@ sub load_loc { return $Loc{$pkg}, sub { $lh = $pkg->get_handle(@_); - $lh = $pkg->get_handle(@_); }; } @@ -205,7 +208,7 @@ sub default_loc { my $str = shift; $str =~ s{((?<!~)(?:~~)*)\[_([1-9]\d*|\*)\]} {$1%$2}g; - $str =~ s{((?<!~)(?:~~)*)\[([A-Za-z#*]\w*),([^\]]+)\]} + $str =~ s{((?<!~)(?:~~)*)\[([A-Za-z#*]\w*),([^\]]+)\]} {"$1%$2(" . _escape($3) . ')'}eg; _default_gettext($str, @_); }; diff --git a/ext/Locale-Maketext-Simple/t/1-basic.t b/ext/Locale-Maketext-Simple/t/1-basic.t index 91d033b795..91d033b795 100644..100755 --- a/ext/Locale-Maketext-Simple/t/1-basic.t +++ b/ext/Locale-Maketext-Simple/t/1-basic.t diff --git a/ext/Locale-Maketext-Simple/t/2-load_po_without_i_default.t b/ext/Locale-Maketext-Simple/t/2-load_po_without_i_default.t new file mode 100755 index 0000000000..47a982307e --- /dev/null +++ b/ext/Locale-Maketext-Simple/t/2-load_po_without_i_default.t @@ -0,0 +1,30 @@ +use strict; +use Test::More; +use FindBin qw($Bin); + +use Locale::Maketext::Simple ( + Path => "$Bin/po_without_i_default", + Style => "gettext", +); + +eval { + require Locale::Maketext::Lexicon; + die unless Locale::Maketext::Lexicon->VERSION(0.20); + require File::Spec; +}; +if ($@) { + plan skip_all => 'No soft dependencies, i_default will not work'; + exit 0; +} + +plan tests => 5; + +loc_lang("en"); +is(loc("Not a lexicon key"), "Not a lexicon key", "Not a lexicon key"); +is(loc("I have got %1 alerts", 65), "I have got 65 alerts", "Got auto key" ); +is(loc("I have acknowledged %1 alerts", 83), "Yo dude, I've been working on these 83 alerts", "Got translation"); + +loc_lang("fr"); +is(loc("system.messages.arbitrary.unique.lexicon.key"), "system.messages.arbitrary.unique.lexicon.key", "No translation" ); +is(loc("I have got %1 alerts", "red"), "Mon Francais red, c'est terrible", "French translated" ); + diff --git a/ext/Locale-Maketext-Simple/t/3-load_po_with_i_default.t b/ext/Locale-Maketext-Simple/t/3-load_po_with_i_default.t new file mode 100755 index 0000000000..a8807106dd --- /dev/null +++ b/ext/Locale-Maketext-Simple/t/3-load_po_with_i_default.t @@ -0,0 +1,31 @@ +use strict; +use Test::More; +use FindBin qw($Bin); + +use Locale::Maketext::Simple ( + Path => "$Bin/po_with_i_default", + Style => "gettext", +); + +eval { + require Locale::Maketext::Lexicon; + die unless Locale::Maketext::Lexicon->VERSION(0.20); + require File::Spec; +}; +if ($@) { + plan skip_all => 'No soft dependencies, i_default will not work'; + exit 0; +} + +plan tests => 6; + +loc_lang("en"); +is(loc("Not a lexicon key"), "Not a lexicon key", "Not a lexicon key"); +is(loc("I have got %1 alerts", "hot"), "Maybe it's because I'm a hot Londoner, that I love London tawn", "Got auto key" ); +is(loc("I have acknowledged %1 alerts", 83), "Yo dude, I've been working on these 83 alerts", "Got translation still in en"); +is(loc("system.messages.arbitrary.unique.lexicon.key"), "This is the default message", "Used i_default because not set in en"); + +loc_lang("fr"); +is(loc("system.messages.arbitrary.unique.lexicon.key"), "This is the default message", "Translated from i_default"); +is(loc("I have got %1 alerts", "red"), "Mon Francais red, c'est terrible", "French translated" ); + diff --git a/ext/Locale-Maketext-Simple/t/po_with_i_default/en.po b/ext/Locale-Maketext-Simple/t/po_with_i_default/en.po new file mode 100644 index 0000000000..0d80b92ef5 --- /dev/null +++ b/ext/Locale-Maketext-Simple/t/po_with_i_default/en.po @@ -0,0 +1,30 @@ +# Locale Maketext Simple language translations +# Copyright (C) All Perl Hackers everywhere +# Ton Voon <ton.voon@opsera.com>, 2009. +# +msgid "" +msgstr "" +"Project-Id-Version: Locale Maketext Simple\n" +"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2009-06-09 14:10+0000\n" +"Last-Translator: Ton Voon <ton.voon@opsera.com>\n" +"Language-Team: English <en@li.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#. $alerts +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "I have got %1 alerts" +msgstr "" + +#. $acknowledged +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "I have acknowledged %1 alerts" +msgstr "Yo dude, I've been working on these %1 alerts" + +#. $acknowledged +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "system.messages.arbitrary.unique.lexicon.key" +msgstr "" + diff --git a/ext/Locale-Maketext-Simple/t/po_with_i_default/fr.po b/ext/Locale-Maketext-Simple/t/po_with_i_default/fr.po new file mode 100644 index 0000000000..8ecfbf761a --- /dev/null +++ b/ext/Locale-Maketext-Simple/t/po_with_i_default/fr.po @@ -0,0 +1,30 @@ +# Locale Maketext Simple language translations +# Copyright (C) All Perl Hackers everywhere +# Ton Voon <ton.voon@opsera.com>, 2009. +# +msgid "" +msgstr "" +"Project-Id-Version: Locale Maketext Simple\n" +"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2009-06-09 14:10+0000\n" +"Last-Translator: Ton Voon <ton.voon@opsera.com>\n" +"Language-Team: French <fr@li.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#. $alerts +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "I have got %1 alerts" +msgstr "Mon Francais %1, c'est terrible" + +#. $acknowledged +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "I have acknowledged %1 alerts" +msgstr "" + +#. $acknowledged +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "system.messages.arbitrary.unique.lexicon.key" +msgstr "" + diff --git a/ext/Locale-Maketext-Simple/t/po_with_i_default/i_default.po b/ext/Locale-Maketext-Simple/t/po_with_i_default/i_default.po new file mode 100644 index 0000000000..7327298688 --- /dev/null +++ b/ext/Locale-Maketext-Simple/t/po_with_i_default/i_default.po @@ -0,0 +1,30 @@ +# Locale Maketext Simple language translations +# Copyright (C) All Perl Hackers everywhere +# Ton Voon <ton.voon@opsera.com>, 2009. +# +msgid "" +msgstr "" +"Project-Id-Version: Locale Maketext Simple\n" +"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2009-06-09 14:10+0000\n" +"Last-Translator: Ton Voon <ton.voon@opsera.com>\n" +"Language-Team: English <en@li.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#. $alerts +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "I have got %1 alerts" +msgstr "Maybe it's because I'm a %1 Londoner, that I love London tawn" + +#. $acknowledged +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "I have acknowledged %1 alerts" +msgstr "In idefault instead of en" + +#. $acknowledged +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "system.messages.arbitrary.unique.lexicon.key" +msgstr "This is the default message" + diff --git a/ext/Locale-Maketext-Simple/t/po_without_i_default/en.po b/ext/Locale-Maketext-Simple/t/po_without_i_default/en.po new file mode 100644 index 0000000000..0d80b92ef5 --- /dev/null +++ b/ext/Locale-Maketext-Simple/t/po_without_i_default/en.po @@ -0,0 +1,30 @@ +# Locale Maketext Simple language translations +# Copyright (C) All Perl Hackers everywhere +# Ton Voon <ton.voon@opsera.com>, 2009. +# +msgid "" +msgstr "" +"Project-Id-Version: Locale Maketext Simple\n" +"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2009-06-09 14:10+0000\n" +"Last-Translator: Ton Voon <ton.voon@opsera.com>\n" +"Language-Team: English <en@li.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#. $alerts +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "I have got %1 alerts" +msgstr "" + +#. $acknowledged +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "I have acknowledged %1 alerts" +msgstr "Yo dude, I've been working on these %1 alerts" + +#. $acknowledged +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "system.messages.arbitrary.unique.lexicon.key" +msgstr "" + diff --git a/ext/Locale-Maketext-Simple/t/po_without_i_default/fr.po b/ext/Locale-Maketext-Simple/t/po_without_i_default/fr.po new file mode 100644 index 0000000000..8ecfbf761a --- /dev/null +++ b/ext/Locale-Maketext-Simple/t/po_without_i_default/fr.po @@ -0,0 +1,30 @@ +# Locale Maketext Simple language translations +# Copyright (C) All Perl Hackers everywhere +# Ton Voon <ton.voon@opsera.com>, 2009. +# +msgid "" +msgstr "" +"Project-Id-Version: Locale Maketext Simple\n" +"POT-Creation-Date: YEAR-MO-DA HO:MI+ZONE\n" +"PO-Revision-Date: 2009-06-09 14:10+0000\n" +"Last-Translator: Ton Voon <ton.voon@opsera.com>\n" +"Language-Team: French <fr@li.org>\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#. $alerts +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "I have got %1 alerts" +msgstr "Mon Francais %1, c'est terrible" + +#. $acknowledged +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "I have acknowledged %1 alerts" +msgstr "" + +#. $acknowledged +#: lib/Opsview/Web/Controller/Root.pm:492 +msgid "system.messages.arbitrary.unique.lexicon.key" +msgstr "" + |