Example #1
0
 public function getNegotiatedLanguageString($acceptLanguage = null)
 {
     $negotiator = new \Negotiation\Negotiator();
     if ($acceptLanguage === null) {
         $acceptLanguage = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] . ', *' : '*';
     }
     $availableLanguages = array_keys($this->_map);
     $preferredLanguage = $negotiator->getBest($acceptLanguage, $availableLanguages);
     return $this->_map[$preferredLanguage->getValue()];
 }
Example #2
0
 public function negotiateLanguage($profile_id = null)
 {
     if ($profile_id) {
         $this->language->profile_id = $profile_id;
     }
     $lang = "en-GB";
     if ($this->getHeader('Accept-Language', false)) {
         $negotiator = new \Negotiation\Negotiator();
         $best = $negotiator->getBest($this->getHeader('Accept-Language'), $this->language->getAllLanguageStrings());
         if ($best) {
             $lang = $best->getValue();
         }
     }
     $this->language->setLanguage($lang, $profile_id);
 }