negotiateLanguage()
negotiateLanguage(array $supported, string $default = 'en-US') : string
Negotiates 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".
Quality factors in the Accept-Language: header are supported, e.g.:
Accept-Language: en-UK;q=0.7, en-US;q=0.6, no, dk;q=0.8
require_once 'HTTP2.php';
$http = new HTTP2();
$langs = array(
'en' => 'locales/en',
'en-US' => 'locales/en',
'en-UK' => 'locales/en',
'de' => 'locales/de',
'de-DE' => 'locales/de',
'de-AT' => 'locales/de',
);
$neg = $http->negotiateLanguage($langs);
$dir = $langs[$neg];
Parameters
array |
$supported |
An associative array of supported languages,
whose values must evaluate to true. |
string |
$default |
The default language to use if none is found. |
Returns
string
— The negotiated language result or the supplied default.