private function getBestLocale(Request $request) { $acceptLanguage = $request->server->get('HTTP_ACCEPT_LANGUAGE'); if (!$acceptLanguage) { return $this->defaultLocale; } $negotiator = new \Negotiation\LanguageNegotiator(); $locale = $negotiator->getBest($acceptLanguage); if (!$locale) { return $this->defaultLocale; } return \Locale::canonicalize($locale->getValue()); }
function getProperLink($url, $info) { /* TODO: use GeoIP to match a geographic area and a language? */ if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { return $url; } $languages = []; foreach ($info as $lang => $url) { $languages[] = $lang; } $negotiator = new \Negotiation\LanguageNegotiator(); $bests = $negotiator->getBest($_SERVER['HTTP_ACCEPT_LANGUAGE'], $languages); if ($bests == null) { return $url; } $lang = $bests->getType(); return $info->{$lang}; }