Dancer::Plugin::SimpleLexicon - Tiny Dancer interface to Locale::Maketext::Lexicon
Version 0.01
In your configuration:
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" 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"
This module is a tiny alternative to Dancer::Plugin::Lexicon. See what it works best for you.
Explanation of the settings.
The path, absolute or relative, to the .po files. The .po files must be named as the defined language tags (see below).
.po
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 languages/it.po must be present.
languages/it.po
If specified, when determining the language, the module will try to lookup the key in the request parameters (param).
param
The key of the session where to read and store the current language. If not specified, the session is not touched.
session
The name of the Dancer var to read when determining the current language.
var
The value of the default language. If not specified, and the looking up in the above values fails, no translation will be done.
The string returned by maketext will be decoded using this encoding. By default is UTF-8.
UTF-8
To disable the decoding, set it to raw.
raw
Return the translation for $string. If optional arguments are provided, pass the string to sprintf with the arguments.
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.
Set the current language to $language_tag, writing it into the session, using the key specified in the session_name value.
session_name
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; } sub localize { my ($self, $string) = @_; my $translated = l($string); return $translated; } 1;
Marco Pessotto, <melmothx at gmail.com>
<melmothx at gmail.com>
Please report any bugs or feature requests to bug-dancer-plugin-simplelexicon at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dancer-Plugin-SimpleLexicon. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-dancer-plugin-simplelexicon at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Dancer::Plugin::SimpleLexicon
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Dancer-Plugin-SimpleLexicon
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Dancer-Plugin-SimpleLexicon
CPAN Ratings
http://cpanratings.perl.org/d/Dancer-Plugin-SimpleLexicon
Search CPAN
http://search.cpan.org/dist/Dancer-Plugin-SimpleLexicon/
Copyright 2014 Marco Pessotto.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Dancer::Plugin::SimpleLexicon::Handler, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dancer::Plugin::SimpleLexicon::Handler
CPAN shell
perl -MCPAN -e shell install Dancer::Plugin::SimpleLexicon::Handler
For more information on module installation, please visit the detailed CPAN module installation guide.