Amon2-Plugin-L10N
view release on metacpan or search on metacpan
lib/Amon2/Plugin/L10N.pm view on Meta::CPAN
=head2 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
},
});
=head2 you can set L<Locale::Maketext::Lexicon> options
# in your MyApp.pm
__PACKAGE__->load_plugins('L10N' => {
accept_langs => [qw/ ja /],
lexicon_options => {
_auto => 0,
},
});
=head2 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',
});
=head1 Translation Step
=head2 installing dependent module of amon2-xgettext.pl
$ cpanm --with-suggests Amon2::Plugin::L10N
dependnt module list in the L<cpanfile> file.
=head2 write your application
=head2 run amon2-xgettext.pl
$ cd your_amon2_proj_base_dir
$ perl amon2-xgettext.pl en ja fr zh-tw
=head2 edit .po files
$ vim po/ja.po
$ vim po/zh-tw.po
=head1 Add Amon2 Context Method
=head2 $c->l10n_language_detection
Language that is detected will return.
=head2 $c->loc($message), $c->loc('foo %1 .. %2 ...', @args);
It will return the text in the appropriate language.
=head1 AUTHOR
Kazuhiro Osawa E<lt>yappo {at} shibuya {dot} plE<gt>
=head1 COPYRIGHT
Copyright 2013- Kazuhiro Osawa
=head1 LICENSE
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=head1 SEE ALSO
L<Amon2>,
L<Locale::Maketext::Lexicon>,
L<HTTP::AcceptLanguage>,
L<amon2-xgettext.pl>
=cut
( run in 1.035 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )