src/Http/Middleware/SetLocale.php
/**
     * Handle an incoming request.
     *
     * @return mixed
     */
Handle an incoming request.
@return mixed
Handle an incoming request . @return mixed
public function handle(Request $request, Closure $next, $locale = '')
    {
        $fallbackLocale = config('locale.fallback_locale');
        $finalLocale = $fallbackLocale;
        if (!empty($locale)) {
            $locale = strtolower($locale);
            $supportedLocales = config('locale.supported_locales');
            $matches = [];
            $this->match($matches, $locale);
            if ($this->isValid($matches)) {
                $tentativeLocale = $this->getLanguageTagFromValidLocale($matches);
                if ($this->isSupported($tentativeLocale, $supportedLocales)) {
                    $finalLocale = $supportedLocales[$tentativeLocale];
                }
            }
        } else {
            $finalLocale = $this->parseFromRequest($request);
        }
        App::setLocale($finalLocale === '*' ? $fallbackLocale : $finalLocale);
        return $next($request);
    }
public function handle ( Request $ request , Closure $ next , $ locale = '' ) { $ fallbackLocale = config ( 'locale.fallback_locale' ) ; $ finalLocale = $ fallbackLocale ; if ( ! empty ( $ locale ) ) { $ locale = strtolower ( $ locale ) ; $ supportedLocales = config ( 'locale.supported_locales' ) ; $ matches = [ ] ; $ this -> match ( $ matches , $ locale ) ; if ( $ this -> isValid ( $ matches ) ) { $ tentativeLocale = $ this -> getLanguageTagFromValidLocale ( $ matches ) ; if ( $ this -> isSupported ( $ tentativeLocale , $ supportedLocales ) ) { $ finalLocale = $ supportedLocales [ $ tentativeLocale ] ; } } } else { $ finalLocale = $ this -> parseFromRequest ( $ request ) ; } App :: setLocale ( $ finalLocale === '*' ? $ fallbackLocale : $ finalLocale ) ; return $ next ( $ request ) ; }
Handle an incoming request.
Handle an incoming request .
// Sets final locale as fallback, in case validation fails // Checks if passed locale is valid and supported // Check if determined locale is a wildcard, if it is set fallback locale