protected function selectPreferredLocale($locales) { foreach ($locales as $locale) { if ($this->configManager->isEnabledLocale($locale['locale'])) { return $locale['locale']; } } }
public function storeLocale() { $storeDriver = $this->config->getStoreDriver(); $key = $this->config->getDefaultKey(); if ($this->locale !== null && !empty($storeDriver)) { $storeDriver = $this->app->make($storeDriver); if ($storeDriver instanceof BaseDriver) { $storeDriver->store($key, $this->locale); return $this->locale; } } }
/** * Generate a URL to a controller action. * * @param string $locale * @return string */ function switch_locale($newLocale) { $route = app('request')->route(); $locale = [ConfigManager::getDefaultKey() => $newLocale]; // The new locale overwrites the current parameters $parameters = array_merge($route->parameters(), $locale); if (null !== $route->getName()) { // Use the same named route return route($route->getName(), $parameters); } elseif (null !== $route->getActionName()) { // Closures are matched like Actions if ($route->getActionName() !== 'Closure') { // Use the same action return action($route->getActionName(), $parameters); } else { // This is a Closure // TODO : Can we do anything? } } // return the current URL return app('request')->url(); }