Class LocaleNegotiator

Description

Negotiates locale and charset based on HTTP headers

This class parses the Accept-Language and Accept-Charset headers in order to determine what are the user settings and use it when auto detecting localization settings.

When PHP2Go loads, and LANGUAGE.AUTO_DETECT is set to true, or CHARSET is set to 'auto', this class is used to determine the new values for these settings, based on the client browser preferences.

Located in /core/LocaleNegotiator.class.php (line 45)


	
			
Variable Summary
array $charsets
array $languages
Method Summary
string negotiateCharset (array $available, string $default)
string negotiateLanguage (array $available, string $default)
string|FALSE _compare (string $value, array $array)
array _parseHeader (string $str)
Variables
array $charsets (line 61)

Set of supported charsets

  • access: private
array $languages (line 53)

Set of supported languages

  • access: private
Methods
static method getInstance (line 82)

Get the singleton of the LocaleNegotiator class

static LocaleNegotiator &getInstance ()
Constructor LocaleNegotiator (line 71)

Class constructor

Loads supported languages and charsets from the HTTP_ACCEPT_LANGUAGE and HTTP_ACCEPT_CHARSET headers.

LocaleNegotiator LocaleNegotiator ()
getSupportedCharsets (line 112)

Get supported charset encodings

Each item of the returned array contains a charset code, along with the quality factor (if lower than 1.0).

array getSupportedCharsets ()
getSupportedLanguages (line 97)

Get supported language codes

Each item of the returned array contains a language code, along with the quality factor (if lower than 1.0).

array getSupportedLanguages ()
negotiateCharset (line 153)

Negotiate the charset encoding

Matches a set of charset codes supported by the application against the ones parsed from the HTTP headers

  • return: Charset
string negotiateCharset (array $available, string $default)
  • array $available: Available charset codes
  • string $default: Default charset code, to be used when negotiation fails
negotiateLanguage (line 133)

Negotiate the language code

This method expects a set of language codes supported by the application and a default language code to be used when negotiation fails.

The set of application language codes is compared with the languages parsed from the request.

  • return: Language code
string negotiateLanguage (array $available, string $default)
  • array $available: Language codes supported by the application
  • string $default: Default language code
_compare (line 198)

Search for a value inside an array, using binary safe and case insensitive comparison

  • return: Array entry in case of success. FALSE in case of error
string|FALSE _compare (string $value, array $array)
  • string $value: Search value
  • array $array: Search base
_parseHeader (line 169)

Internal method that parses Accept-* headers

  • return: Parsed header
array _parseHeader (string $str)
  • string $str: Raw header

Documentation generated on Sun, 07 Oct 2007 19:27:19 -0300 by phpDocumentor 1.3.2