-
-
17 Oct 2013 11:13:28 UTC
- Distribution: HTTP-AcceptLanguage
- Module version: 0.02
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues (2)
- Testers (3796 / 1 / 10)
- Kwalitee
Bus factor: 0- 97.99% Coverage
- License: perl_5
- Perl: v5.8.5
- Activity
24 month- Tools
- Download (12.44KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 3 contributors- Kazuhiro Osawa <yappo {at} shibuya {dot} pl>
-
Kazuhiro Osawa
-
tokuhirom
- Dependencies
- none
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
HTTP::AcceptLanguage - Accept-Language header parser and find available language
HOW DO I USE THIS MODULE WITH
WITH CGI.pm
use HTTP::AcceptLanguage; my $lang = HTTP::AcceptLanguage->new($ENV{HTTP_ACCEPT_LANGUAGE})->match(qw/ en fr es ja zh-tw /);
WITH raw PSGI
use HTTP::AcceptLanguage; my $lang = HTTP::AcceptLanguage->new($env->{HTTP_ACCEPT_LANGUAGE})->match(qw/ en fr es ja zh-tw /);
WITH Plack::Request
use HTTP::AcceptLanguage; my $lang = HTTP::AcceptLanguage->new($req->header('Accept-Language'))->match(qw/ en fr es ja zh-tw /);
SYNOPSIS
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
DESCRIPTION
HTTP::AcceptLanguage is HTTP Accept-Language header parser And you can find available language by Accept-Language header.
METHODS
new($ENV{HTTP_ACCEPT_LANGUAGE})
It to specify a string of Accept-Language header.
match(@available_language)
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}).
languages
Returns are arranged in order of quality language list parsed.
AUTHOR
Kazuhiro Osawa <yappo {at} shibuya {dot} pl>
COPYRIGHT
Copyright 2013- Kazuhiro Osawa
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
RFC2616, I18N::AcceptLanguage
Module Install Instructions
To install HTTP::AcceptLanguage, copy and paste the appropriate command in to your terminal.
cpanm HTTP::AcceptLanguage
perl -MCPAN -e shell install HTTP::AcceptLanguage
For more information on module installation, please visit the detailed CPAN module installation guide.