コード例 #1
0
 /**
  * Sets and stores the locale in the session.
  *
  * @param SetLocaleRequest $request
  * @return mixed
  */
 public function setLocale(SetLocaleRequest $request)
 {
     $locale = $request->input('locale');
     if (!$this->repository->isAvailable($locale)) {
         return redirect()->back()->withErrors("Locale {$locale} is not available");
     }
     session()->set($this->getSessionKey(), $locale);
     return redirect()->back();
 }
コード例 #2
0
 /**
  * Bind data to the view.
  *
  * @param View $view
  */
 public function compose(View $view)
 {
     $view->with(['localized' => $this->repository->isLocalized(), 'currentLocale' => app()->getLocale(), 'availableLocales' => $this->repository->getAvailable()]);
 }
コード例 #3
0
ファイル: SetLocale.php プロジェクト: czim/laravel-cms-core
 /**
  * @param \Illuminate\Http\Request $request
  * @return string
  */
 protected function getRequestLocale($request)
 {
     $locales = array_unique(array_merge([$this->repository->getDefault()], $this->repository->getAvailable()));
     return $request->getPreferredLanguage($locales);
 }