Ejemplo n.º 1
1
 /**
  * @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);
 }
Ejemplo n.º 2
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();
 }
Ejemplo n.º 3
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()]);
 }