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 the locale is determined by env, use that
            // Note that this is how per-locale route caching is performed.
            if ( ! $locale) {
                $locale = $this->getForcedLocale();
            }
        }

        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;
            }
            // but if hideDefaultLocaleInURL is false, we have
            // to retrieve it from the browser...
            else {
                $this->currentLocale = $this->getCurrentLocale();
            }
        }

        $this->app->setLocale($this->currentLocale);

        // Regional locale such as de_DE, so formatLocalized works in Carbon
        $regional = $this->getCurrentLocaleRegional();
        $suffix = $this->configRepository->get('laravellocalization.utf8suffix');
        if ($regional) {
            setlocale(LC_TIME, $regional . $suffix);
            setlocale(LC_MONETARY, $regional . $suffix);
        }

        return $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 the locale is determined by env, use that
            // Note that this is how per-locale route caching is performed.
            if ( ! $locale) {
                $locale = $this->getForcedLocale();
            }
        }

        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;
            }
            // but if hideDefaultLocaleInURL is false, we have
            // to retrieve it from the browser...
            else {
                $this->currentLocale = $this->getCurrentLocale();
            }
        }

        $this->app->setLocale($this->currentLocale);

        // Regional locale such as de_DE, so formatLocalized works in Carbon
        $regional = $this->getCurrentLocaleRegional();
        $suffix = $this->configRepository->get('laravellocalization.utf8suffix');
        if ($regional) {
            setlocale(LC_TIME, $regional . $suffix);
            setlocale(LC_MONETARY, $regional . $suffix);
        }

        return $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 the locale is determined by env, use that // Note that this is how per-locale route caching is performed. if ( ! $ locale ) { $ locale = $ this -> getForcedLocale ( ) ; } } 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 ; } // but if hideDefaultLocaleInURL is false, we have // to retrieve it from the browser... else { $ this -> currentLocale = $ this -> getCurrentLocale ( ) ; } } $ this -> app -> setLocale ( $ this -> currentLocale ) ; // Regional locale such as de_DE, so formatLocalized works in Carbon $ regional = $ this -> getCurrentLocaleRegional ( ) ; $ suffix = $ this -> configRepository -> get ( 'laravellocalization.utf8suffix' ) ; if ( $ regional ) { setlocale ( LC_TIME , $ regional . $ suffix ) ; setlocale ( LC_MONETARY , $ regional . $ suffix ) ; } 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)
Set and return current locale .