HTTP::negotiateLanguage

HTTP::negotiateLanguage -- Negotiate language with the user's browser

Synopsis

require_once 'HTTP.php';

string HTTP::negotiateLanguage (array $supported, string $default = 'en_US')

Description

Negotiate language with the user's browser through the Accept-Language HTTP header or the user's host address. Language codes are generally in the form "ll" for a language spoken in only one country, or "ll-CC" for a language spoken in a particular country. For example, U.S. English is "en-US", while British English is "en-UK". Portugese as spoken in Portugal is "pt-PT", while Brazilian Portugese is "pt-BR". Two-letter country codes can be found in the ISO 3166 standard.

Quantities in the Accept-Language: header are supported, for example:
Accept-Language: en-UK;q=0.7, en-US;q=0.6, no;q=1.0, dk;q=0.8

Parameter

Return value

string - a language code

Note

This function can be called statically

The returned language is only a hint! Sending the accepted languages by the client is optional. The language settings of the browser do not have to meet the user's native language - for example a german traveller in a spanish internet cafe. You can improve your result by combining it with the result of Net_Geo . Apart from that you should still give the user the chance to manually choose his prefered language. menu.