Mojolicious::Plugin::LocaleTextDomainOO - I18N(GNU getext) for Mojolicious.
# Mojolicious
$self->plugin('LocaleTextDomainOO');
# Mojolicious::Lite
plugin 'LocaleTextDomainOO';
# your app in startup method
sub startup {
# setup plugin
$self->plugin('LocaleTextDomainOO',
{
file_type => 'po', # or 'mo'. default: po
default => 'ja', # default en
plugins => [ # more Locale::TextDomain::OO plugins.
qw/ +Your::Special::Plugin # default Expand::Gettext::DomainAndCategory plugin onry.
/],
languages => [ qw( en-US en ja-JP ja de-DE de ) ],
# Mojolicious::Plugin::I18N like options
no_header_detect => $boolean, # option. default: false
support_url_langs => [ qw( en ja de ) ], # option
support_hosts => { # option
'mojolicious.ru' => 'ru',
'mojolicio.us' => 'en'
}
}
);
# loading lexicon files
$self->lexicon(
{
search_dirs => [qw(/path/my_app/locale)],
gettext_to_maketext => $boolean, # option
decode => $boolean, # option
data => [ '*::' => '*.po' ],
}
);
...
}
Locale::TextDomain::OO is a internationalisation(I18N) tool of perl OO interface. Mojolicious::Plugin::LocaleTextDomainOO is internationalization plugin for Mojolicious.
This module is similar to Mojolicious::Plugin::I18N. But, Locale::MakeText is not using "text domain" and more...
plugin LocaleTextDomainOO => { file_type => 'po' };
Gettext lexicon File type. default to po
.
plugin LocaleTextDomainOO => { default => 'ja' };
Default language. default to en
.
plugin LocaleTextDomainOO => { languages => [ 'en-US', 'en', 'ja-JP', 'ja' ] };
plugin LocaleTextDomainOO => { plugins => [ qw /Your::LocaleTextDomainOO::Plugin/ ] };
Add plugin. default using Locale::TextDomain::OO::Plugin::Expand::Gettext::DomainAndCategory and Locale::TextDomain::OO::Plugin::Language::LanguageOfLanguages plugin onry.
plugin LocaleTextDomainOO => { support_url_langs => [ 'en', 'ja', 'de' ] };
Detect language from URL. see Mojolicious::Plugin::I18N option.
plugin LocaleTextDomainOO => { support_hosts => { 'mojolicious.ru' => 'ru', 'mojolicio.us' => 'en' } };
Detect Host header and use language for that host. see Mojolicious::Plugin::I18N option.
plugin LocaleTextDomainOO => { no_header_detect => 1 };
Off header detect. see Mojolicious::Plugin::I18N option.
# Mojolicious Lite
my $loc = app->locale;
Returned Locale::TextDomain::OO object.
app->lexicon(
{
search_dirs => [qw(your/my_app/locale)],
gettext_to_maketext => $boolean,
decode => $boolean, # default true. *** utf8 flaged ***
data => [
'*::' => '*.po',
'*:CATEGORY:DOMAIN' => '*/test.po',
],
}
);
Gettext '*.po' or '*.mo' file as lexicon. See Locale::TextDomain::OO::Lexicon::File::PO Locale::TextDomain::OO::Lexicon::File::MO
app->language('ja');
my $language = app->language;
Set or Get language.
# In controller
app->__('hello');
app->__x('hello, {name}', name => 'World');
# In template
<%= __ 'hello' %>
<%= __x 'hello, {name}', name => 'World' %>
See Locale::TextDomain::OO::Plugin::Expand::Gettext
# In controller
app->__p(
'time', # Context (msgctxt)
'hello'
);
# In template
<%= __p 'time', 'hello' %>
See Locale::TextDomain::OO::Plugin::Expand::Gettext
See Locale::TextDomain::OO::Plugin::Expand::Gettext
# In controller
app->__d(
'domain', # Text Domain
'hello'
);
# In template
<%= __d 'domain', 'hello' %>
# begin, end
<%= __begin_d 'domain' %>
<%= __ 'hello' %>
<%= __ 'hello2' %>
<%= __end_d %>
See Locale::TextDomain::OO::Plugin::Expand::Gettext::DomainAndCategory
See Locale::TextDomain::OO::Plugin::Expand::Gettext::DomainAndCategory
Mojolicious::Plugin::LocaleTextDomainOO inherits all methods from Mojolicious::Plugin and implements the following new ones.
$plugin->register(Mojolicious->new);
Register plugin in Mojolicious application.
# debug mode on
BEGIN { $ENV{MOJO_I18N_DEBUG} = 1 }
# or
MOJO_I18N_DEBUG=1 perl script.pl
Munenori Sugimura clicktx@gmail.com
Locale::TextDomain::OO, Mojolicious, Mojolicious::Guides, http://mojolicious.org.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
Mojolicious::Plugin::LocaleTextDomainOO uses Mojolicious::Plugin::I18N code. Here is LICENSE of Mojolicious::Plugin::I18N
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.