Get the request locale.

The local is the original language of the client
e.g fr => locale = fr_FR
e.g en => locale [ en_US, en_EN]

@return string|null
162057
public function locale()
    {
        $accept_language = $this->getHeader('accept_language');

        $tmp = explode(';', $accept_language)[0];

        preg_match('/^([a-z]+(?:-|_)?[a-z]+)/i', $tmp, $match);

        return end($match);
    }
22230
protected function _getCurrentLanguage() {
        if (!isset($_SERVER['REQUEST_URI'])) {
            // Probably CLI context. Return the default locale
            return Garp_I18n::getDefaultLocale();
        }
        $requestUri = $_SERVER['REQUEST_URI'];
        $bits = explode('/', $requestUri);
        // remove empty values
        $bits = array_filter($bits, 'strlen');
        // reindex the array
        $bits = array_values($bits);
        $bits = array_map('strtolower', $bits);
        $locales = $this->_getPossibleLocales();
        if (array_key_exists(0, $bits) && in_array($bits[0], $locales)) {
            return $bits[0];
        }
        return Garp_I18n::getDefaultLocale();
    }
46770
public function getSiteLanguage()
    {
        if (is_null($this->language) && ($request = $this->requestStack->getMasterRequest())) {
            $this->language = $request->get('language', $request->getLocale());
        }

        return $this->language;
    }
454101
@Override
    public Locale getLocale() {
        if (super.getSession(false) == null) {
            return super.getLocale();
        }

        final IUserInstance userInstance =
                this.userInstanceManager.getUserInstance(this.getWrappedRequest());
        final LocaleManager localeManager = userInstance.getLocaleManager();
        final List<Locale> locales = localeManager.getLocales();
        return locales.get(0);
    }
1274735
public function getLocale()
	{
        $locales = explode(',', $this->_meta->locale);

		for($i = 0; $i < count($locales); $i++ ) {
			$locale = $locales[$i];
			$locale = trim($locale);
			$locales[$i] = $locale;
		}

		return $locales;
	}
469913
public function htmlLang()
    {
        $request = $this->requestStack->getCurrentRequest();
        $locale = $request ? $request->getLocale() : $this->locale;

        return str_replace('_', '-', $locale);
    }
161761
private function getFromHttpAcceptedLanguagesServer()
    {
        $httpAcceptLanguage = $this->request->server('HTTP_ACCEPT_LANGUAGE');

        // @codeCoverageIgnoreStart
        if ( ! class_exists('Locale') || empty($httpAcceptLanguage))
            return null;
        // @codeCoverageIgnoreEnd

        $locale = Locale::acceptFromHttp($httpAcceptLanguage);

        if ($this->isSupported($locale)) return $locale;

        return null;
    }
772249
protected function getLocaleCurrency(Request $request)
    {
        $currentLocale = $request->getLocale();
        $locale        = $this->container->get('locale.repository')->findOneBy(['code' => $currentLocale]);

        if (null !== $locale && $locale->getCurrency() instanceof Currency) {
            return $locale->getCurrency()->getCode();
        }

        return null;
    }
434848
public function getLocaleFromAuthenticatedUser()
    {

        $user = $this->findAuthenticatedUser();

        return (null !== $user && $user->getLocale()) ? $user->getLocale() : 'es';
    }
634318
public function getLocale(HttpRequest $request)
    {
        if ($this->locale) {
            return $this->locale;
        }

        // get locale from language list
        $constraint = new Locale();
        foreach ($request->getLanguages() as $language) {
            if (!$this->validator->validate($language, $constraint)->has(0)) {
                return $language;
            }
        }

        // get default locale
        return $request->getLocale();
    }
1169605
@Deprecated
    public static Locale getLocale() {
        Locale locale = null;
        FacesContext facesContext = FacesContext.getCurrentInstance();

        if (facesContext != null && facesContext.getViewRoot() != null) {
            locale = facesContext.getViewRoot().getLocale();

            if (locale == null) {
                locale = Locale.getDefault();
            }
        }
        else {
            locale = Locale.getDefault();
        }
        return locale;
    }
301115
private function get_user_locale() {
		global $wp_version;
		if ( version_compare( $wp_version, '4.7.0', '>=' ) ) {
			return get_user_locale();
		}
		$user = wp_get_current_user();
		if ( $user ) {
			$locale = $user->locale;
		}

		return $locale ? $locale : get_locale();
	}
826476
protected function getLocale($locale)
    {
        $result = null;
        if ($locale instanceof LocaleEntity) {
            $result = $locale;
        } elseif (is_string($locale) && $locale !== '') {
            $result = $this->app->make(LocaleRepository::class)->findApproved($locale);
        }

        return $result;
    }
1308694
protected function getUrlLanguage($locale = null)
    {
        // Check if the functionality is activated
        if (!ConfigQuery::isMultiDomainActivated()) {
            return null;
        }

        // If we don't have a locale value, use the locale value in the session
        if (!$locale) {
            $locale = $this->getCurrentEditionLocale();
        }

        return LangQuery::create()->findOneByLocale($locale)->getUrl();
    }
684300
public function getDefaultLocale()
    {
        try {
            return $this->entityManager->getRepository(Locale::class)->findOneBy(['msIsDefault' => true]);
        } catch (TableNotFoundException $e) {
            return null;
        }
    }
1165612
public function getCurrentLocale()
    {
        if ( ! is_null($this->currentLocale))
            return $this->currentLocale;

        if ($this->useAcceptLanguageHeader())
            return $this->negotiateLocale();

        // Get application default language
        return $this->getDefaultLocale();
    }
290389
public function getLocale()
	{
		if (!$this->locale) {
            $locale = self::getStaticLocale();
            if (!$locale) {
                $locale = StdLocale::getDefault();
            }

            $this->setLocale($locale);
		}
		
		return $this->locale;
	}