Amon2-Plugin-L10N
view release on metacpan or search on metacpan
after_detection_hook => sub {
my($c, $lang) = shift;
return 'zh-cn' if $lang eq 'zh'; # use zh-cn.po file
return $lang;
},
});
for your CLI
__PACKAGE__->load_plugins('L10N' => {
default_lang => 'ja',
accept_langs => [qw/ en ja /],
before_detection_hook => sub {
my $c = shift;
return unless $NEV{CLI_MODE}; # CLI_MODE is example key
return 'ja' if $ENV{LANG} =~ /ja/i;
return 'en' if $ENV{LANG} =~ /en/i;
return; # use default lang
},
});
you can set Locale::Maketext::Lexicon options
# in your MyApp.pm
__PACKAGE__->load_plugins('L10N' => {
accept_langs => [qw/ ja /],
lexicon_options => {
_auto => 0,
},
});
you can implement L10N class yourself
package L10N;
use strict;
use warnings;
use parent 'Locale::Maketext';
use File::Spec;
use Locale::Maketext::Lexicon +{
'ja' => [ Gettext => File::Spec->catfile('t', 'po', 'ja.po') ],
_preload => 1,
_style => 'gettext',
_decode => 1,
};
# in your MyApp.pm
__PACKAGE__->load_plugins('L10N' => {
accept_langs => [qw/ ja /],
l10n_class => 'L10N',
});
Translation Step
installing dependent module of amon2-xgettext.pl
$ cpanm --with-suggests Amon2::Plugin::L10N
dependnt module list in the cpanfile file.
write your application
run amon2-xgettext.pl
$ cd your_amon2_proj_base_dir
$ perl amon2-xgettext.pl en ja fr zh-tw
edit .po files
$ vim po/ja.po
$ vim po/zh-tw.po
Add Amon2 Context Method
$c->l10n_language_detection
Language that is detected will return.
$c->loc($message), $c->loc('foo %1 .. %2 ...', @args);
It will return the text in the appropriate language.
AUTHOR
Kazuhiro Osawa <yappo {at} shibuya {dot} pl>
COPYRIGHT
Copyright 2013- Kazuhiro Osawa
LICENSE
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
SEE ALSO
Amon2, Locale::Maketext::Lexicon, HTTP::AcceptLanguage,
amon2-xgettext.pl
( run in 0.521 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )