Drupal 8  8.0.2
UserAgent Class Reference

Static Public Member Functions

static getBestMatchingLangcode ($http_accept_language, $langcodes, $mappings=array())
 

Detailed Description

Provides user agent related utility functions.

Member Function Documentation

static getBestMatchingLangcode (   $http_accept_language,
  $langcodes,
  $mappings = array() 
)
static

Identifies user agent language from the Accept-language HTTP header.

The algorithm works as follows:

  • map user agent language codes to available language codes.
  • order all user agent language codes by qvalue from high to low.
  • add generic user agent language codes if they aren't already specified but with a slightly lower qvalue.
  • find the most specific available language code with the highest qvalue.
  • if 2 or more languages are having the same qvalue, respect the order of them inside the $languages array.

We perform user agent accept-language parsing only if page cache is disabled, otherwise we would cache a user-specific preference.

Parameters
string$http_accept_languageThe value of the "Accept-Language" HTTP header.
array$langcodesAn array of available language codes to pick from.
array$mappings(optional) Custom mappings to support user agents that are sending non standard language codes. No mapping is assumed by default.
Returns
string The selected language code or FALSE if no valid language can be identified.

Referenced by SelectLanguageForm\buildForm(), LanguageNegotiationBrowser\getLangcode(), and UserAgentTest\testGetBestMatchingLangcode().

Here is the caller graph for this function:


The documentation for this class was generated from the following file: