Returns the expected locale for a given territory

@param string $territory Territory for which the locale is being searched
@return string|null Locale string or null when no locale has been found
548785
public static function getLocaleToTerritory($territory)
    {
        $territory = strtoupper($territory);
        if (array_key_exists($territory, self::$_territoryData)) {
            return self::$_territoryData[$territory];
        }

        return null;
    }
841681
public function findCanonical(string $locale): ?Scope
    {
        $canonicals = $this->config->get('canonicals');

        if (!isset($canonicals[$locale])) {
            return null;
        }

        $scope = $this->findByRoot($canonicals[$locale]);

        return $scope->setCustomRoot(Root::fromString($canonicals[$locale]));
    }
1317337
public function instance($domain = 'app', $locale = null)
    {
        $locale = $locale ?: $this->locale;

        // The ID code is something like: 'en/system', 'en/app' or 'en/file_manager'
        $id = $locale .'/' .$domain;

        // Returns the Language domain instance, if it already exists.
        if (isset($this->instances[$id])) return $this->instances[$id];

        return $this->instances[$id] = new Language($this, $domain, $locale);
    }
1103109
protected function getDomain(?string $domain = null) : ?string
    {
        $domain = $domain ?? $this->appUrl;

        if ($domain === null) {
            return null;
        }

        return $this->trim(str_replace(['http:', 'https:'], '', $domain), '/');
    }
753763
public static function getByLocale($locale)
    {
        if (!$locale) {
            return null;
        }

        if ($locale instanceof Locale) {
            return $locale;
        }

        if (!static::$locales_by_title) {
            static::$locales_by_title = [];
            foreach (Locale::getCached() as $localeObj) {
                static::$locales_by_title[$localeObj->Locale] = $localeObj;
            }
        }

        // Get filtered locale
        return isset(static::$locales_by_title[$locale]) ? static::$locales_by_title[$locale] : null;
    }
427528
public function getAllByLocaleAndDomain($locale, $domain)
    {
        return $this->createQueryBuilder('tu')
            ->select('tu, te')
            ->leftJoin('tu.translations', 'te')
            ->where('tu.domain = :domain')
            ->andWhere('te.locale = :locale')
            ->setParameter('domain', $domain)
            ->setParameter('locale', $locale)
            ->getQuery()
            ->getArrayResult();
    }
1326448
protected function getCurrentLocale($locale = null)
    {
        return null !== $locale
            ? LocaleUtils::formatLocale($locale)
            : $this->getLocale();
    }
566821
static function getLangByUrl($url = null)
    {
        if ($url === null) {
            return null;
        } else {
            $language = Lang::find()->where('url = :url', [':url' => $url])->one();
            if ( $language === null ) {
                return null;
            }else{
                return $language;
            }
        }
    }
324411
protected function getValue($string, $domain, $locale)
    {
        if (!$domain) {
            $domain = 'default';
        }

        $this->loadDomain($domain, $locale);

        // We have to treat 'languages', 'default', 'modules' etc. domains differently.
        if (!(isset($GLOBALS['TL_LANG'][$domain]) && is_array($GLOBALS['TL_LANG'][$domain]))
            && (substr($domain, 0, 2) != 'tl_')
        ) {
            $lang = $GLOBALS['TL_LANG'];
        } else {
            if (!is_array($GLOBALS['TL_LANG'][$domain])) {
                return $string;
            }
            $lang = $GLOBALS['TL_LANG'][$domain];
        }

        $chunks = explode('.', $string);

        while (($chunk = array_shift($chunks)) !== null) {
            if (!array_key_exists($chunk, $lang)) {
                return $string;
            }

            $lang = $lang[$chunk];
        }

        return $lang;
    }
1222199
public function getLocale() : ?string 
    {
        if ( ! $this->hasLocale()) {
            $this->setLocale($this->getDefaultLocale());
        }
        return $this->locale;
    }
522088
public function getLocaleString($key)
    {
        $level = &$this->localeData;
        $keys = explode('.', $key);

        foreach ($keys as $key) {
            if (isset($level[$key])) {
                $level = &$level[$key];
            } else {
                return null;
            }
        }

        return $level;
    }
858016
public function getLocaleName(string $locale, ?string $displayLocale = null): ?string
    {
        return Locales::getName($locale, $displayLocale);
    }
585401
public function getLanguageForCountry($country = null)
    {
        if ($country === null) {
            $country = $this->_country;
        }
        // Since getLanguage defaults to EN, check so we actually have a match
        $language = KlarnaCountry::getLanguage($country);
        if (KlarnaCountry::checkLanguage($country, $language)) {
            return $language;
        }
        return false;
    }
1224721
public function textDomain( $textDomain = self::DEFAULT_TEXT_DOMAIN,
                                $locale     = null )
    {
        $translator = $this->getTranslator();
        $locale     = $locale ?: $translator->getLocale();

        if ( ! isset( $translator->myMessages[$textDomain][$locale] ) )
        {
            $translator->loadMyMessages( $textDomain, $locale );
        }

        if ( ! isset( $translator->messages[$textDomain][$locale] ) )
        {
            $translator->loadMessages( $textDomain, $locale );
        }

        $my     = $translator->myMessages[$textDomain][$locale];
        $global = $translator->messages[$textDomain][$locale];

        if ( $my instanceof TextDomain )
        {
            $my = $my->getArrayCopy();
        }
        else if ( empty( $my ) )
        {
            $my = array();
        }

        if ( $global instanceof TextDomain )
        {
            $global = $global->getArrayCopy();
        }
        else if ( empty( $global ) )
        {
            $global = array();
        }

        return array_replace( $global, $my );
    }
334252
public function getLanguageCode($lang = null)
    {
        $parts = $this->_callInternalLocale('parseLocale', null, $lang, false);
        return isset($parts['language']) ? $parts['language'] : null;
    }
185046
private function getFallbackLocale($locale = null)
    {
        if ($locale && $this->isLocaleCountryBased($locale)) {
            if ($fallback = $this->getLanguageFromCountryBasedLocale($locale)) {
                return $fallback;
            }
        }

        $locales = $this->getLocales();

        foreach ($locales as $code) {
            if ($this->getTranslationByLocaleKey($code) !== null)
                return $code;
        }

        return app()->make('config')->get('revy.translatable.fallback_locale');
    }
344787
public function findAllNotDisabled($locale, $domain = null)
    {
        $qb = $this->createQueryBuilder('t');
        $qb
            ->select('t')
            ->where('t.locale = :locale')
            ->andWhere('t.status != :statusstring')
            ->setParameter('statusstring', Translation::STATUS_DISABLED)
            ->setParameter('locale', $locale);
        if (!\is_null($domain) && !empty($domain)) {
            $qb->andWhere('t.domain = :tdomain')
                ->setParameter('tdomain', $domain);
        }

        return $qb->getQuery()->getResult();
    }