public function testDetectLanguageWithUserWithSettings() { $expected = 'it'; $request = $this->getMockBuilder(Request::class)->setMethods(['getHeaders'])->getMock(); $request->expects($this->never())->method('getHeaders'); $settings = new \stdClass(); $settings->localization = new \stdClass(); $settings->localization->language = $expected; $user = $this->getMockBuilder(User::class)->getMock(); $user->expects($this->once())->method('getSettings')->with($this->equalTo('Core'))->willReturn($settings); $this->assertSame($expected, $this->localeService->detectLanguage($request, $user)); }
/** * @param MvcEvent $e * @param $lang */ protected function setLocale(MvcEvent $e, $lang) { $translator = $e->getApplication()->getServiceManager()->get('translator'); $locale = $this->localeService->getLocaleByLanguage($lang); setlocale(LC_ALL, array($locale . ".utf8", $locale . ".iso88591", $locale, substr($locale, 0, 2), 'de_DE.utf8', 'de_DE', 'de')); Locale::setDefault($locale); $translator->setLocale($locale); $routeMatch = $e->getRouteMatch(); if ($routeMatch && $routeMatch->getParam('lang') === null) { $routeMatch->setParam('lang', $lang); } $e->getRouter()->setDefaultParam('lang', $lang); }
/** * Change locale. * * @return void */ public function changeAction() { $redirect = $this->getRequest()->getHeader('Referer')->uri()->getPath(); $newLocale = (string) $this->params()->fromQuery('set'); $locales = Locales::getAvailableLocales(); if (array_key_exists($newLocale, $locales)) { if ($this->authService->hasIdentity()) { $user = $this->authService->getIdentity(); $this->userService->changeLocaleByUser($user, $newLocale); $user->setLanguage($newLocale); $this->authService->getStorage()->write($user); } $session = new Container('locale'); $session->locale = $newLocale; } return $this->redirect()->toUrl($redirect); }
public function getAvailableTranslatableLocales() { return Locales::getAvailableLocales(); }