public function Request::getPreferredLanguage in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/http-foundation/Request.php \Symfony\Component\HttpFoundation\Request::getPreferredLanguage()
Returns the preferred language.
Parameters
array $locales An array of ordered available locales:
Return value
string|null The preferred locale
File
- vendor/
symfony/ http-foundation/ Request.php, line 1542
Class
- Request
- Request represents an HTTP request.
Namespace
Symfony\Component\HttpFoundationCode
public function getPreferredLanguage(array $locales = null) {
$preferredLanguages = $this
->getLanguages();
if (empty($locales)) {
return isset($preferredLanguages[0]) ? $preferredLanguages[0] : null;
}
if (!$preferredLanguages) {
return $locales[0];
}
$extendedPreferredLanguages = array();
foreach ($preferredLanguages as $language) {
$extendedPreferredLanguages[] = $language;
if (false !== ($position = strpos($language, '_'))) {
$superLanguage = substr($language, 0, $position);
if (!in_array($superLanguage, $preferredLanguages)) {
$extendedPreferredLanguages[] = $superLanguage;
}
}
}
$preferredLanguages = array_values(array_intersect($extendedPreferredLanguages, $locales));
return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $locales[0];
}