Stefan Hornburg (Racke)
and 1 contributors

NAME

HTTP::ClientDetect::Language - Lookup the client's preferred language

VERSION

Version 0.03

SYNOPSIS

    use HTTP::ClientDetect::Language;
    my $lang_detect = HTTP::ClientDetect::Language->new(server_default => "en_US");
    # inside a Dancer route
    get '/detect' => sub {
        my $req = request;
        my $lang = $lang_detect->language($req);
    }

ACCESSORS

server_default

The server_default should be set in the constructor and defaults to en_US. This will be always returned if the lookup fails

available_languages

Accessor to an arrayref of languages available on the server side. Please use the short version (de, not de_DE), otherwise the check will be too restrictive.

SUBROUTINES/METHODS

language($request_obj)

Return the preferred language of the request. The request object should an object which has the methods accept_language or header

From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html:

 The Accept-Language request-header field is similar to Accept, but
 restricts the set of natural languages that are preferred as a
 response to the request. Language tags are defined in section 3.10.

       Accept-Language = "Accept-Language" ":"
                         1#( language-range [ ";" "q" "=" qvalue ] )
       language-range  = ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" )

 Each language-range MAY be given an associated quality value which
 represents an estimate of the user's preference for the languages
 specified by that range. The quality value defaults to "q=1". For
 example,

       Accept-Language: da, en-gb;q=0.8, en;q=0.7

 would mean: "I prefer Danish, but will accept British English and
 other types of English." A language-range matches a language-tag if
 it exactly equals the tag, or if it exactly equals a prefix of the
 tag such that the first tag character following the prefix is "-".
 The special range "*", if present in the Accept-Language field,
 matches every tag not matched by any other range present in the
 Accept-Language field.

      Note: This use of a prefix matching rule does not imply that
      language tags are assigned to languages in such a way that it is
      always true that if a user understands a language with a certain
      tag, then this user will also understand all languages with tags
      for which this tag is a prefix. The prefix rule simply allows the
      use of prefix tags if this is the case.

 The language quality factor assigned to a language-tag by the
 Accept-Language field is the quality value of the longest language-
 range in the field that matches the language-tag. If no language-
 range in the field matches the tag, the language quality factor
 assigned is 0. If no Accept-Language header is present in the
 request, the server

 SHOULD assume that all languages are equally acceptable. If an
 Accept-Language header is present, then all languages which are
 assigned a quality factor greater than 0 are acceptable.

  It might be contrary to the privacy expectations of the user to send
  an Accept-Language header with the complete linguistic preferences
  of the user in every request

browser_languages($request)

This method returns the parsed and sorted list of language preferences set in the browser, when the first element has higher priority.

language_short($request_obj)

Return the short language version (i.e.), the language name without the country part.

check_language_name

Returns a normalized version of the language name, lower case for the language, upper case for the country. Undef it was not possible to validate it.

AUTHOR

Marco Pessotto, <melmothx at gmail.com>

BUGS

Please report any bugs or feature requests to bug-interchange6-plugin-autodetect at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTTP-ClientDetect. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc HTTP::ClientDetect::Language

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2013 Marco Pessotto.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.