NAME
Plack::Middleware::I18N - language detection
SYNOPSIS
use Plack::Builder;
builder {
enable 'I18N', i18n => $i18n;
...
};
DESCRIPTION
Plack::Middleware::I18N detects client's languages and set $env
variables.
Language detection
All detected languages are validated against available languages.
From path
When PATH_INFO
contains something like /en/path/to
, then en
is detected as a language and PATH_INFO
is changed to /path/to
.
From session
When psgix.session
contains plack.i18n.language
then it is used as a language. Session option is set after every detection.
From HTTP_ACCEPT
Detects language from HTTP_ACCEPT
header using I18N::AcceptLanguage.
From custom callback
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';
};
$env
parameters
Plack::Middleware::I18N registers the following $env
parameters:
plack.i18n
-
Holds Plack::I18N instance.
plack.i18n.language
-
Current detected language. A shortcut for
$env-
{'plack.i18n'}->language>. plack.i18n.handle
-
A shortcut for
$env-
{'plack.i18n'}->handle($env->{'plack.i18n.language'})>.
OPTIONS
- i18n
-
Plack::I18N instance.
- use_path
-
Whether detect language from URL.
- use_session
-
Whether detect language from session.
- use_header
-
Whether detect language from
HTTP_ACCEPT
. - custom_cb
-
Whether detect language from a custom callback.
LICENSE
Copyright (C) Viacheslav Tykhanovskyi.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
AUTHOR
vti <viacheslav.t@gmail.com>