Plack::Middleware::I18N - language detection
use Plack::Builder; builder { enable 'I18N', i18n => $i18n; ... };
Plack::Middleware::I18N detects client's languages and set $env variables.
$env
All detected languages are validated against available languages.
When PATH_INFO contains something like /en/path/to, then en is detected as a language and PATH_INFO is changed to /path/to.
PATH_INFO
/en/path/to
en
/path/to
When psgix.session contains plack.i18n.language then it is used as a language. Session option is set after every detection.
psgix.session
plack.i18n.language
HTTP_ACCEPT_LANGUAGE
Detects language from HTTP_ACCEPT_LANGUAGE header using I18N::AcceptLanguage.
Sometimes a more sophisticated language detection is needed. Thus a custom callback can be provided. For example:
enable 'I18N', custom_cb => sub { my ($env, $lang) = @_; return 'de'; };
Plack::Middleware::I18N registers the following $env parameters:
plack.i18n
Holds Plack::I18N instance.
Current detected language. A shortcut for $env-{'plack.i18n'}->language>.
$env-
plack.i18n.handle
A shortcut for $env-{'plack.i18n'}->handle($env->{'plack.i18n.language'})>.
Plack::Middleware
prepare_app
call($env)
wrap($app, @args)
Plack::I18N instance.
Whether detect language from URL.
Whether detect language from session.
Whether detect language from HTTP_ACCEPT_LANGUAGE.
Whether detect language from a custom callback.
Viacheslav Tykhanovskyi, <viacheslav.t@gmail.com>
Copyright (C) 2015, Viacheslav Tykhanovskyi
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
To install Plack::I18N, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Plack::I18N
CPAN shell
perl -MCPAN -e shell install Plack::I18N
For more information on module installation, please visit the detailed CPAN module installation guide.