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
Detects language from HTTP_ACCEPT 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::I18N instance.
Whether detect language from URL.
Whether detect language from session.
Whether detect language from HTTP_ACCEPT.
Whether detect language from a custom callback.
Copyright (C) Viacheslav Tykhanovskyi.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
vti <viacheslav.t@gmail.com>
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.