Dancer-Plugin-SimpleLexicon

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

SYNOPSIS
    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"

SETTINGS
    This module is a tiny alternative to Dancer::Plugin::Lexicon. See what
    it works best for you.

    Explanation of the settings.

  path
    The path, absolute or relative, to the `.po' files. The `.po' files must
    be named as the defined language tags (see below).

  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
    `languages/it.po' must be present.

  param_name
    If specified, when determining the language, the module will try to
    lookup the key in the request parameters (`param').

  session_name
    The key of the `session' where to read and store the current language.
    If not specified, the session is not touched.

  var_name
    The name of the Dancer `var' to read when determining the current
    language.

  default
    The value of the default language. If not specified, and the looking up
    in the above values fails, no translation will be done.

  encoding
    The string returned by maketext will be decoded using this encoding. By
    default is `UTF-8'.

    To disable the decoding, set it to `raw'.

EXPORT
  l($string, @args)
    Return the translation for $string. If optional arguments are provided,
    pass the string to sprintf with the arguments.

  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.

  set_language($language_tag)
    Set the current language to $language_tag, writing it into the session,
    using the key specified in the `session_name' value.

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;
      }
  
      sub localize {
          my ($self, $string) = @_;
          my $translated = l($string);
          return $translated;



( run in 0.840 second using v1.01-cache-2.11-cpan-39bf76dae61 )