/** * @param $request * @param callable $next * @return mixed */ public function handle($request, \Closure $next) { if ($this->auth->check()) { $this->app->setLocale($this->auth->user()->getLocale()); } return $next($request); }
/** * Handle the event. */ public function handle() { if ($locale = $this->preferences->get('streams::locale')) { $this->application->setLocale($locale); $this->config->set('app.locale', $locale); } }
public function handle(Request $request, Closure $next) { $default = $request->session()->get('locale', 'en'); $locale = $request->input('locale', $default); $locale = Str::substr($locale, 0, 2); $request->session()->put('locale', $locale); $this->app->setLocale($locale); return $next($request); }
/** * Sets the app locale * * @param string $locale * @param bool $session * @return void */ public function setAppLocale($locale = null, $session = true) { $locale = $locale ?: $this->session->get('_locale', null); if ($locale) { $this->app->setLocale($locale); if ($session) { $this->session->put('_locale', $locale); } $this->setTimeLocale($locale); } }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * * @return mixed */ public function handle($request, Closure $next) { $this->app->setLocale($this->settings->get('user.language', 'en')); $langDir = ['left' => 'left', 'right' => 'right']; if (trans('general.direction') == 'rtl') { $langDir['left'] = 'right'; $langDir['right'] = 'left'; } $this->viewFactory->share('langDir', $langDir); return $next($request); }
/** * Handle the command. * * @param Application $app * @param Repository $config * @param Request $request * @param PreferenceRepositoryInterface $preferences */ function handle(Application $app, Repository $config, Request $request, PreferenceRepositoryInterface $preferences) { // Set using admin locale if in admin. if ($request->segment(1) === 'admin' && ($locale = $preferences->get('streams::admin_locale'))) { $app->setLocale($locale->getValue()); $config->set('app.locale', $locale->getValue()); } // Set using public locale if NOT in admin. if (!defined('LOCALE') && $request->segment(1) !== 'admin' && ($locale = $preferences->get('streams::public_locale'))) { $app->setLocale($locale->getValue()); $config->set('app.locale', $locale->getValue()); } }
/** * Set and return current locale * * @param string $locale Locale to set the App to (optional) * * @return string Returns locale (if route has any) or null (if route does not have a locale) */ public function setLocale($locale = null) { if (empty($locale) || !is_string($locale)) { // If the locale has not been passed through the function // it tries to get it from the first segment of the url $locale = $this->request->segment(1); } if (!empty($this->supportedLocales[$locale])) { $this->currentLocale = $locale; } else { // if the first segment/locale passed is not valid // the system would ask which locale have to take // it could be taken by the browser // depending on your configuration $locale = null; // if we reached this point and hideDefaultLocaleInURL is true // we have to assume we are routing to a defaultLocale route. if ($this->hideDefaultLocaleInURL()) { $this->currentLocale = $this->defaultLocale; } else { $this->currentLocale = $this->getCurrentLocale(); } } $this->app->setLocale($this->currentLocale); // Regional locale such as de_DE, so formatLocalized works in Carbon $regional = $this->getCurrentLocaleRegional(); if ($regional) { setlocale(LC_TIME, $regional . '.utf8'); } return $locale; }
/** * Set and return current locale * * @param string $locale Locale to set the App to (optional) * * @return string Returns locale (if route has any) or null (if route does not have a locale) */ public function setLocale($locale = null) { if (empty($locale) || !is_string($locale)) { // If the locale has not been passed through the function // it tries to get it from the first segment of the url $locale = $this->request->segment(1); } if (!empty($this->supportedLocales[$locale])) { $this->currentLocale = $locale; } else { // if the first segment/locale passed is not valid // the system would ask which locale have to take // it could be taken by the browser // depending on your configuration $locale = null; // if we reached this point and hideDefaultLocaleInURL is true // we have to assume we are routing to a defaultLocale route. if ($this->hideDefaultLocaleInURL()) { $this->currentLocale = $this->defaultLocale; } else { $this->currentLocale = $this->getCurrentLocale(); } } //save locale in session session('locale', $this->currentLocale); $this->app->setLocale($this->currentLocale); return $locale; }
/** * Look for locale=LOCALE in the query string. * * @param Request $request * @param \Closure $next * @return mixed */ public function handle(Request $request, Closure $next) { if (defined('LOCALE')) { return $next($request); } if ($locale = $request->get('_locale')) { if ($locale) { $request->session()->put('_locale', $locale); } else { $request->session()->remove('_locale'); } return $this->redirect->to($request->path()); } if ($locale = $request->session()->get('_locale')) { $this->application->setLocale($locale); $this->config->set('_locale', $locale); } if (!$locale) { $this->application->setLocale($this->config->get('streams::locales.default')); } return $next($request); }
/** * Set the current application locale. * * @param string $locale * @return void */ public function setLocale($locale) { parent::setLocale($locale); $localeMapping = $this['config']->get('locale-mapping'); $mappedValue = array_get($localeMapping, 'locales.' . $locale); if ($mappedValue) { $mappedCategories = array_get($localeMapping, 'categories'); if (in_array(LC_ALL, $mappedCategories)) { setlocale(LC_ALL, $mappedValue); } else { foreach ($mappedCategories as $mappedCategory) { setlocale($mappedCategory, $mappedValue); } } } }
/** * Set and return current locale. * * @param string|null $locale * * @return string */ public function setLocale($locale = null) { if (empty($locale) || !is_string($locale)) { // If the locale has not been passed through the function // it tries to get it from the first segment of the url $locale = $this->request()->segment(1); } if ($this->isSupportedLocale($locale)) { $this->setCurrentLocale($locale); } else { // if the first segment/locale passed is not valid the system would ask which locale have to take // it could be taken by the browser depending on your configuration $locale = null; $this->getCurrentOrDefaultLocale(); } $this->app->setLocale($this->getCurrentLocale()); return $locale; }
/** * Handle the command. * * @param Repository $config * @param Application $application */ public function handle(Repository $config, Application $application) { // First trigger to resolve. $application->make('translator'); /* * Change the lang loader so we can * add a few more necessary override * paths to the API. */ $application->singleton('translation.loader', function ($application) { return new Loader($application['files'], $application['path.lang']); }); /* * Re-bind the translator so we can use * the new loader defined above. */ $application->singleton('translator', function ($application) { $loader = $application->make('translation.loader'); // When registering the translator component, we'll need to set the default // locale as well as the fallback locale. So, we'll grab the application // configuration so we can easily get both of these values from there. $locale = $application['config']['app.locale']; $trans = new Translator($loader, $locale); $trans->setFallback($application['config']['app.fallback_locale']); return $trans; }); /* * Set the locale if LOCALE is defined. * * LOCALE is defined first thing in our * HTTP Kernel. Respect it! */ if (defined('LOCALE')) { $application->setLocale(LOCALE); $config->set('app.locale', LOCALE); } // Set our locale namespace. $application->make('translator')->addNamespace('streams', realpath(__DIR__ . '/../../../resources/lang')); }
/** * Set app locale if we have a query parameter named * lang then it will be used else we check for sub domain * If nothing found fallback will be used * * @return void */ private function setLocale() { $availableLangs = $this->config->get('app.available_languages', []); if ($this->input->has('lang')) { $lang = $this->input->input('lang'); if (in_array($this->input->input('lang'), $availableLangs)) { $this->app->setLocale($lang); Session::put(self::SESSION_LOCALE, $lang); return; } } $subDomain = $this->router->getCurrentRoute(); if (!empty($subDomain)) { $subDomain = $subDomain->getParameter('locale'); $this->app->setLocale($subDomain); return; } if ($this->session->has(self::SESSION_LOCALE)) { $this->app->setLocale($this->session->get(self::SESSION_LOCALE)); return; } }
/** * Set the current application locale. * * @param string $locale * @return void * @static */ public static function setLocale($locale) { \Illuminate\Foundation\Application::setLocale($locale); }
public function testSetLocaleSetsLocaleAndFiresLocaleChangedEvent() { $app = new Application(); $app['config'] = $config = m::mock('StdClass'); $config->shouldReceive('set')->once()->with('app.locale', 'foo'); $app['translator'] = $trans = m::mock('StdClass'); $trans->shouldReceive('setLocale')->once()->with('foo'); $app['events'] = $events = m::mock('StdClass'); $events->shouldReceive('fire')->once()->with('locale.changed', array('foo')); $app->setLocale('foo'); }
/** * Set the current locale. * * @param string $locale */ public function setCurrentLocale($locale) { $this->app->setLocale($locale); }
/** * Set fallback localization * */ public function fallback() { $this->flushLocale(); $this->app->setLocale($this->fallback); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string|null $guard * @return mixed */ public function handle($request, Closure $next, $guard = null) { $locale = $this->determinerManager->determineLocale($request); $this->app->setLocale($locale); return $next($request); }