Mojolicious::Plugin::I18n - Intenationalization Plugin


Mojolicious documentation  | view source Contained in the Mojolicious distribution.

Index


NAME

Top

Mojolicious::Plugin::I18n - Intenationalization Plugin

SYNOPSIS

Top

  # Mojolicious
  $self->plugin('i18n');
  % languages 'de';
  <%=l 'hello' %>

  # Mojolicious::Lite
  plugin 'i18n' => {namespace => 'MyApp::I18N'};
  <%=l 'hello' %>

  # Lexicon
  package MyApp::I18N::de;
  use Mojo::Base 'MyApp::I18N';

  our %Lexicon = (hello => 'hallo');

  1;

DESCRIPTION

Top

Mojolicious::Plugin::I18n adds Locale::Maketext support to Mojolicious. All you have to do besides using this plugin is to add as many lexicon classes as you need. Languages can usually be detected automatically from the Accept-Languages request header.

This plugin can save a lot of typing, since it will generate the following code by default.

  # $self->plugin('i18n');
  package MyApp::I18N;
  use base 'Locale::Maketext';
  package MyApp::I18N::en;
  use base 'MyApp::I18N';
  our %Lexicon = (_AUTO => 1);
  1;

Namespace and default language of generated code are affected by their respective options. The default lexicon class will only be generated if it doesn't already exist.

OPTIONS

Top

default

  # Mojolicious::Lite
  plugin i18n => {default => 'en'};

Default language, defaults to en.

namespace

  # Mojolicious::Lite
  plugin i18n => {namespace => 'MyApp::I18N'};

Lexicon namespace, defaults to the application class followed by ::I18N.

HELPERS

Top

l

  <%=l 'hello' %>
  $self->l('hello');

Translate sentence.

languages

  <% languages 'de'; %>
  $self->languages('de');

Change languages.

METHODS

Top

Mojolicious::Plugin::I18n inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

  $plugin->register;

Register plugin hooks and helpers in Mojolicious application.

SEE ALSO

Top

Mojolicious, Mojolicious::Guides, http://mojolicio.us.


Mojolicious documentation  | view source Contained in the Mojolicious distribution.