private function prepareDisplayProperties($lang)
 {
     $locale = $this->config->findLocaleByLanguage($lang);
     $nameOfLanguage = \Locale::getDisplayName($lang, $locale);
     $nameOfCountry = \Locale::getDisplayLanguage($lang, \Locale::getDefault());
     $countryCode = \Locale::getRegion($locale);
     return [$nameOfLanguage, $nameOfCountry, $countryCode];
 }
Exemple #2
0
 public function recognize(MvcEvent $event)
 {
     if (!$this->config->getAvailableLanguages()) {
         return false;
     }
     $lang = $this->config->getDefaultLanguage();
     /** @var Request $request */
     $request = $event->getRequest();
     $routeMatchLang = $this->getRouteMatchLanguage($event);
     $browserLang = null;
     if ($this->config->shouldRedirectToRecognizedLanguage()) {
         $browserLang = $this->getBrowseAcceptLanguage($request->getHeaders());
     }
     if ($routeMatchLang || $browserLang) {
         $lang = $routeMatchLang ? $routeMatchLang : $browserLang;
     }
     $locale = $this->config->findLocaleByLanguage($lang);
     return [$lang, $locale, $routeMatchLang, $browserLang];
 }
Exemple #3
0
 public function testConstructor_WithNotEmptyConfig_WhenShouldRedirectIsDisabled()
 {
     $testedObject = new LangConfig($this->prepareConfig(false));
     $this->assertSame('en', $testedObject->getDefaultLanguage());
     $this->assertSame('en_GB', $testedObject->getDefaultLocale());
     $this->assertSame(['de', 'en', 'pl', 'pt-br'], $testedObject->getAvailableLanguages());
     $this->assertSame('de', $testedObject->findLanguageByLocale('de_DE'));
     $this->assertSame('pt_BR', $testedObject->findLocaleByLanguage('pt-br'));
     $this->assertFalse($testedObject->shouldRedirectToRecognizedLanguage());
 }