logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

I18N::AcceptLanguage - Matches language preference to available languages

Authors

       Christian Gilmore <cag@us.ibm.com>

Availability

       This module is available on CPAN worldwide and requires perl version 5.6.1 or higher be installed.

Description

I18N::AcceptLanguage matches language preference to available languages per rules defined in RFC 2616,
       section 14.4: HTTP/1.1 - Header Field Definitions - Accept-Language.

Name

       I18N::AcceptLanguage - Matches language preference to available languages

Notes

       Case Sensitivity
         Language matches are done in a case-insensitive manner but results  are  case-sensitive  to  the  value
         found in the SUPPORTED_LANGUAGES list.

Private Methods

       debug( [ BOOLEAN ] )
         A get/set method that returns the value of debug, set by the optional method argument.

       defaultLanguage( [ LANGUAGE ] )
         A get/set method that returns the value of defaultLanguage, set by the optional method argument.

       strict( [ BOOLEAN ] )
         A get/set method that returns the value of strict, set by the optional method argument.

Public Methods

       accepts( CLIENT_PREFERENCES, SUPPORTED_LANGUAGES )
         Returns the highest priority common language between client and server. If no common language is found,
         the  defaultLanguage  is  returned. If defaultLanuage is also not set, an empty string is returned. The
         method expects two arguments:

         CLIENT_PREFERENCES
           A string in the same format defined in RFC 2616, quoted here:

             1#( ( ( 1*8ALPHA *( "-" 1*8ALPHA ) ) | "*" ) [ "'" "q" "=" qvalue ] )

           Examples:

             da, en-gb;q=0.8, en;q=0.7

             en-us, ja, *

         SUPPORTED_LANGUAGES
           A reference to a list of language ranges supported by the server.

       new( [ OPTIONS ] )
         Returns a new I18N::AcceptLanguage object. The method accepts the following key/value pair options:

         debug
           A boolean set to either 0 or 1. When set to 1, debug messages will be printed to STDOUT. The value of
           debug defaults to 0.

         defaultLanguage
           A string representing the server's default language choice. The value of defaultLanguage defaults  to
           an empty string.

         strict
           A  boolean  set  to  either  0  or  1.  When set to 1, the software strictly conforms to the protocol
           specification. When set to 0, the software  will  perform  a  secondary,  aggressive  language  match
           regardless  of country (ie, a client asking for only en-gb will get back en-us if the server does not
           accept en-gb or en but does accept en-us). The last matching language in the supported languages list
           will be chosen. The value of strict defaults to 1.

See Also

       RFC 2616

Synopsis

         use I18N::AcceptLanguage;

         my $supportedLanguages = [( 'en-us', 'fr' )];

         my $acceptor = I18N::AcceptLanguage->new();
         my $language = $acceptor->accepts($ENV{HTTP_ACCEPT_LANGUAGE},
                                           $supportedLanguages);

See Also