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
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
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
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') {
return $Loc{$pkg}, sub {
$lh = $pkg->get_handle(@_);
- $lh = $pkg->get_handle(@_);
};
}
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, @_);
};
--- /dev/null
+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" );
+
--- /dev/null
+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" );
+
--- /dev/null
+# 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 ""
+
--- /dev/null
+# 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 ""
+
--- /dev/null
+# 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"
+
--- /dev/null
+# 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 ""
+
--- /dev/null
+# 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 ""
+