NAME
Dancer2::Plugin::Locale - Localize your Dancer2 application
VERSION
This document describes Dancer2::Plugin::Locale version 0.01
SYNOPSIS
In your app:
use Dancer2;
use Dancer2::Plugin::Locale;
…
locale->maketext('You are [numf,_1] of [numf,_2].', 42, 99);
…
and from template
<div id="req_msg">[% locale.maketext('You have [quant,_1,request,requests].', req_count) %]</div>
DESCRIPTION
Adds a locale
keyword for your code and templates.
INTERFACE
locale
A lazy façade to get a locale handle suitable to the request. The locale object is a CLDR aware maketext format object.
It will be based on the session’s locale value if possible, then a configured default if possible, then 'en'.
… TODO, sorry I needed to get this on CPAN for a consumer but will finish it ASAP …
The object, in detail
… TODO, sorry I needed to get this on CPAN for a consumer but will finish it ASAP …
CLDR
… TODO, sorry I needed to get this on CPAN for a consumer but will finish it ASAP …
Available locales.
The locales available are determined by the lexicon files found in the appdir’s locale/
directory.
The name of each file must be a normalized version (See Locales::normalize_tag() in Locales) of an acceptable ISO tag. and end in with the extension .json
.
Tip: To make them available to your UI you could simply symlink …/locale/
to …/public/locale
.
Lexicon
A lexicon is a simple key/value hash where the key is the phrase and the value is the translation.
For example,
'Hello World' => 'Bonjour Monde'
The hash must be written in JSON format and be utf8 encoded.
Don’t be afraid of non-ASCII characters, just put them in the file as the character and it will work fine (if it doesn’t then it can help you track down bugs faster, win win!).
"I ♥︎ Dancer2!" : "私は♥︎ダンサー2"
Bracket Notation
… TODO, sorry I needed to get this on CPAN for a consumer but will finish it ASAP …
Misc Info
Only load the lexicon data you need!
… TODO, sorry I needed to get this on CPAN for a consumer but will finish it ASAP …
per app/route loading/unloading of specific lexicon
… TODO, sorry I needed to get this on CPAN for a consumer but will finish it ASAP …
only load the keys you use
Localization Principles
… TODO, sorry I needed to get this on CPAN for a consumer but will finish it ASAP …
Extracting and Vetting phrases from your app
… TODO, sorry I needed to get this on CPAN for a consumer but will finish it ASAP …
TODOs
TODO items in the POD obviously, will list more if there are any left after the next version.
DIAGNOSTICS
Throws no errors of its own.
The only warning is during startup if you have a mis-named file in your locale/
directory:
<Skipping un-normalized locale named lexicon (%s.json) …
>
CONFIGURATION AND ENVIRONMENT
The default locale is “en”, you can change it via Dancer2 configuration like so:
plugins:
Locales:
default_locale: ja
DEPENDENCIES
INCOMPATIBILITIES
None reported.
BUGS AND LIMITATIONS
No bugs have been reported.
Please report any bugs or feature requests to bug-dancer2-plugin-locale@rt.cpan.org
, or through the web interface at http://rt.cpan.org.
AUTHOR
Daniel Muey <http://drmuey.com/cpan_contact.pl>
LICENCE AND COPYRIGHT
Copyright (c) 2015, Daniel Muey <http://drmuey.com/cpan_contact.pl>
. All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
DISCLAIMER OF WARRANTY
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.