HTTP::AcceptLanguage - Accept-Language header parser and find available language
use HTTP::AcceptLanguage; my $lang = HTTP::AcceptLanguage->new($ENV{HTTP_ACCEPT_LANGUAGE})->match(qw/ en fr es ja zh-tw /);
use HTTP::AcceptLanguage; my $lang = HTTP::AcceptLanguage->new($env->{HTTP_ACCEPT_LANGUAGE})->match(qw/ en fr es ja zh-tw /);
use HTTP::AcceptLanguage; my $lang = HTTP::AcceptLanguage->new($req->header('Accept-Language'))->match(qw/ en fr es ja zh-tw /);
Good example of the input and output.
# If language quality is the same then order by match method's input list my $accept_language = HTTP::AcceptLanguage->new('en;q=0.5, ja;q=0.1'); $accept_language->match(qw/ th da ja /); # -> ja $accept_language->match(qw/ en ja /); # -> en my $accept_language = HTTP::AcceptLanguage->new('en, da'); $accept_language->match(qw/ da en /); # -> en $accept_language->match(qw/ en da /); # -> en
You can obtain the order of preference of the available languages list of client
my $accept_language = HTTP::AcceptLanguage->new('en, ja;q=0.3, da;q=1, *;q=0.29, ch-tw'); $accept_language->languages; # -> en, da, ch-tw, ja, *
You can use the 0.01 version spec. (next version is deplicated)
local $HTTP::AcceptLanguage::MATCH_PRIORITY_0_01_STYLE = 1; my $accept_language = HTTP::AcceptLanguage->new('en, da'); $accept_language->match(qw/ da en /); # -> da $accept_language->match(qw/ en da /); # -> en
HTTP::AcceptLanguage is HTTP Accept-Language header parser And you can find available language by Accept-Language header.
It to specify a string of Accept-Language header.
By your available language list, returns the most optimal language.
If language-quality has the same value, is a priority order of the new($ENV{HTTP_ACCEPT_LANGUAGE}).
Returns are arranged in order of quality language list parsed.
Kazuhiro Osawa <yappo {at} shibuya {dot} pl>
Copyright 2013- Kazuhiro Osawa
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
RFC2616, I18N::AcceptLanguage
To install HTTP::AcceptLanguage, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::AcceptLanguage
CPAN shell
perl -MCPAN -e shell install HTTP::AcceptLanguage
For more information on module installation, please visit the detailed CPAN module installation guide.