Dancer-Plugin-SimpleLexicon
view release on metacpan or search on metacpan
lib/Dancer/Plugin/SimpleLexicon.pm view on Meta::CPAN
param_name: lang
var_name: lang
default: en
encoding: UTF-8
langs:
en: "US English"
de: "Deutsch"
nl: "Netherlands"
se: "Sweden"
it: "Italiano"
In your module
use Dancer ':syntax';
use Dancer::Plugin::SimpleLexicon;
var lang => 'it';
my $string = l('Hello %s', 'Marco');
# assuming languages/it.po have a translation for this, will return "Ciao Marco"
=head1 SETTINGS
This module is a tiny alternative to L<Dancer::Plugin::Lexicon>. See
what it works best for you.
Explanation of the settings.
=head2 path
The path, absolute or relative, to the C<.po> files. The C<.po> files
must be named as the defined language tags (see below).
=head2 langs
An array of keys/values with the language tag and the full name on the
language.
Please note that if you define a language "it", the file
C<languages/it.po> B<must be present>.
=head2 param_name
If specified, when determining the language, the module will try to
lookup the key in the request parameters (C<param>).
=head2 session_name
The key of the C<session> where to read and store the current language.
If not specified, the session is not touched.
=head2 var_name
The name of the Dancer C<var> to read when determining the current language.
=head2 default
The value of the default language. If not specified, and the looking up
in the above values fails, no translation will be done.
=head2 encoding
The string returned by maketext will be decoded using
this encoding. By default is C<UTF-8>.
To disable the decoding, set it to C<raw>.
=head1 EXPORT
=head2 l($string, @args)
Return the translation for $string. If optional arguments are
provided, pass the string to sprintf with the arguments.
=head2 language
Return the current language used, returning the long name of the
language as defined in the configuration.
The priority set is follow: param, session, var, default. The first
wins, assuming it was defined in the config. Unclear if it's the right
thing to do. TODO: make this configurable or at runtime.
=head2 set_language($language_tag)
Set the current language to $language_tag, writing it into the
session, using the key specified in the C<session_name> value.
=head1 Dancer::Template::TemplateFlute integration
In the configuration:
engines:
template_flute:
i18n:
class: My::Lexicon
method: localize
plugins:
SimpleLexicon:
path: languages
session_name: lang
param_name: lang
var_name: lang
default: en
encoding: UTF-8
langs:
en: "US English"
de: "Deutsch"
nl: "Netherlands"
se: "Sweden"
And write the tiny class My::Lexicon wit the following content:
package My::Lexicon;
use Dancer ':syntax';
use Dancer::Plugin::SimpleLexicon;
use Encode;
sub new {
my $class = shift;
my $self = {};
bless $self, $class;
}
( run in 0.805 second using v1.01-cache-2.11-cpan-2398b32b56e )