Returns the locale present in the current url, if any.

@param  integer $segment     Index of the segment containing locale info
@return string
335051
public function localeFromRequest($segment = 0)
    {
        $url = $this->request->getUri();
        return $this->getLocaleFromUrl($url, $segment);
    }
1353649
public static function getRegion($locale)
    {
        $parts = explode('-', str_replace('_', '-', $locale));

        if (count($parts) === 1) {
            return '';
        }

        $region = end($parts);

        if (strlen($region) === 4) {
            return '';
        }

        if ($region === 'POSIX') {
            $region = 'US';
        }

        return strtoupper($region);
    }
144083
public function locale($locale = null)
    {
        // Set the locale if a valid local is passed
        if ($locale
            && ($locales = Config::get('decoy.site.locales'))
            && is_array($locales)
            && isset($locales[$locale])) {
            return Session::put('locale', $locale);
        }

        // Return the current locale or default to first one.  Store it in a local var
        // so that multiple calls don't have to do any complicated work.  We're assuming
        // the locale won't change within a single request.
        if (!$this->locale) {
            $this->locale = Session::get('locale', $this->defaultLocale());
        }

        return $this->locale;
    }
858016
public function getLocaleName(string $locale, ?string $displayLocale = null): ?string
    {
        return Locales::getName($locale, $displayLocale);
    }
431835
private function getIndexOf($segment){
		if($segment instanceof Segment){
			foreach($this->segments as $index=>$other){
				if($other === $segment){
					return $index;
				}
			}
		}else{
			foreach($this->segments as $index=>$other){
				if($other->getName() === $segment){
					return $index;
				}
			}
		}
		return false;
	}
126083
public function getUri( $locale = null )
    {
        if ( empty( $locale ) )
        {
            $locale = $this->getLocale();
        }

        return '/app/'
             . $locale
             . '/user/view/'
             . rawurlencode( $this->displayName );
    }
1121239
public function getLocalizedUri($newLocale) {
		$uri = $this->getRequest()->getRequestUri();
		if ($uri === '/') {
			return '/' . $newLocale;
		}
		return preg_replace("/\/" . preg_quote($this->getLocale()) . "(\/|$)/", "/" . preg_quote($newLocale) . "$1", $uri);
	}
1137930
public function setSegment($segment)
    {
        if (array_key_exists($segment, $this->segments)) {
            return $this->segments[$segment];
        }
        // $reg = "#\[!--\sBEGIN\s$segment\s--\]<\/text:p>(.*?)<text:p\s.*>\[!--\sEND\s$segment\s--\]#sm";
        $reg = "#\[!--\sBEGIN\s$segment\s--\](.*?)\[!--\sEND\s$segment\s--\]#smU";
        if (preg_match($reg, html_entity_decode($this->contentXml), $m) == 0) {
            throw new OdfException("'$segment' segment not found in the document");
        }
        $this->segments[$segment] = new Segment($segment, $m[1], $this);
        return $this->segments[$segment];
    }
1348213
public function getClientPreferredLocale()
    {
        if (null !== $this->locale) {
            $locale = $this->locale;

        } else {
            // Get detector
            $detector = $this->getDetector();

            // Detect user's preferred locale
            $detector->detect();

            // get the locale from detector
            $locale = $detector->getLocale();
        }

        // return the active locale
        return $locale;
    }
1251589
@Override
    public Locale getLocale() {
        ServletRESTRequestImpl ret = castRequest();
        if (ret != null)
            return ret.getLocale();
        return null;
    }
1346197
protected function getLocaleFromUrl($url)
    {
        $parts = explode('/', $url);
        $locale = $parts[1];

        foreach ($this->availableLanguages as $language) {
            if ($locale === substr($language['locale'], 0, 2)) {
                return $language['locale'];
            }
        }

        return false;
    }
595381
public function segment($segment)
    {
        $segments = $this->segments;

        return isset($segments[$segment - 1]) ? $segments[$segment - 1] : false;
    }
1326448
protected function getCurrentLocale($locale = null)
    {
        return null !== $locale
            ? LocaleUtils::formatLocale($locale)
            : $this->getLocale();
    }
733351
public function getUrlCahceKey($com,$langcode,$suffix,$segments){
		$key='url:'.$com.':'.$langcode.$suffix;
		$seg='';
		if(is_array($segments)){
			foreach($segments as $k=>$v){
				if(is_object($v)){
					$v=json_encode($v);
					}
				$seg.=$k.'='.$v.',';
				}
			}
		$key.=':'.SHA1($seg);
		return $key;
		}
476315
public static function setLocale($locale = null) {
        $app = app();
        $currentLocale = $app->config->get('app.locale');
        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 = $app->request->segment(1);
        }
        if (!in_array($locale, $app->config->get('sirgrimorum.crudgenerator.list_locales'))) {
            $locale = $currentLocale;
        }

        //if (!empty($this->supportedLocales[$locale])) {
        $currentLocale = $locale;
        //}

        $app->setLocale($currentLocale);

        return $currentLocale;
    }
318610
public function getRewrittenUrl($locale)
    {
        $rewritingUrl = RewritingUrlQuery::create()
            ->filterByViewLocale($locale)
            ->filterByView($this->getRewrittenUrlViewName())
            ->filterByViewId($this->getId())
            ->filterByRedirected(null)
            ->findOne()
        ;

        if ($rewritingUrl) {
            $url = $rewritingUrl->getUrl();
        } else {
            $url = null;
        }

        return $url;
    }
556137
private function getLocaleRegexUrls()
    {
        $urls = array();
        foreach ($this->getLocales() as $locale) {
            if ($locale->hasACustomUrl()) {
                $urls[] =  preg_quote($locale->getUrl(), '/');
            }
        }
        return $urls;
    }