Get the full path to the file containing the localized strings for a specific locale.

@param string $localeID The ID of the locale

@return string|null Returns the full path of the file if it exists, null otherwise
15955
private function locateLanguageFile($localeID)
    {
        $localeIDAlternatives = $this->getLocaleIDAlternatives($localeID);
        $result = null;
        foreach ($localeIDAlternatives as $localeIDAlternative) {
            $languageFile = $this->getLanguageFilePath($localeIDAlternative);
            if (is_file($languageFile)) {
                $result = $languageFile;
                break;
            }
        }

        return $result;
    }
579459
public function getUrl($locale = null)
    {
        if (null === $locale) {
            $locale = $this->getLocale();
        }

        return URL::getInstance()->retrieve($this->getRewrittenUrlViewName(), $this->getId(), $locale)->toString();
    }
950142
public static function getSourceLocaleString(string $default = 'en-US'): string
    {
        $view = static::get('view', null, false);

        return $view ? (string)$view->getSourceLocale() : $default;
    }
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;
    }
889091
public function deleteLocaleGroups($localeID)
    {
        foreach ([
            self::GROUPNAME_LOCALE_ADMINISTRATORS,
            self::GROUPNAME_TRANSLATORS,
            self::GROUPNAME_ASPIRING_TRANSLATORS,
        ] as $parentGroupName) {
            $path = "/$parentGroupName/$localeID";
            $group = Group::getByPath($path);
            if ($group !== null) {
                $group->delete();
            }
        }
    }
937764
private function installTranslations($localeID, Package $package = null)
    {
        if ($package === null) {
            $localStats = $this->localFactory->getCoreStats($localeID);
            $shownDirectoryName = '/' . DIRNAME_APPLICATION . '/' . DIRNAME_LANGUAGES;
        } else {
            $localStats = $this->localFactory->getPackageStats($package, $localeID);
            $shownDirectoryName = '/' . DIRNAME_PACKAGES . '/' . $package->getPackageHandle() . '/' . DIRNAME_LANGUAGES;
        }
        $directory = dirname($localStats->getFilename());
        if (!$this->fs->isDirectory($directory)) {
            if ($this->fs->makeDirectory($directory, DIRECTORY_PERMISSIONS_MODE_COMPUTED, true, true) !== true) {
                throw new Exception(t('Failed to create the directory for the language file. Please be sure that the %s directory is writable', $shownDirectoryName));
            }
        }
        if (!$this->fs->isWritable($directory)) {
            throw new Exception(t('Please be sure that the %s directory is writable', $shownDirectoryName));
        }
        if ($package === null) {
            $coreVersion = $this->config->get('concrete.version_installed');
            $translations = $this->remoteProvider->fetchCoreTranslations($coreVersion, $localeID);
        } else {
            $translations = $this->remoteProvider->fetchPackageTranslations($package->getPackageHandle(), $package->getPackageVersion(), $localeID);
        }
        $saved = @$this->fs->put($localStats->getFilename(), $translations, true) !== false;
        unset($translations);
        if ($saved === false) {
            throw new Exception(t('Failed to save the language file: please be sure that PHP can write files in the directory %s', $shownDirectoryName));
        }
    }
739913
protected function findLocale()
    {
        $locale = null;

        if (PHP_SAPI == 'cli') {
            $locale = getenv('LANG');
        } else if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) && extension_loaded('intl')) {
            $locale = \Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']);
        }

        return $locale;
    }
1013244
private String getFilePath(ExtensionId id, String fileExtension)
    {
        String encodedId = PathUtils.encode(id.getId());
        String encodedVersion = PathUtils.encode(id.getVersion().toString());
        String encodedType = PathUtils.encode(fileExtension);

        return encodedId + File.separator + encodedVersion + File.separator + encodedId + '-' + encodedVersion + '.'
            + encodedType;
    }
629645
public static String getName(String localeID){
        String tmpLocaleID;
        // Convert BCP47 id if necessary
        if (localeID != null && !localeID.contains("@") && getShortestSubtagLength(localeID) == 1) {
            tmpLocaleID = forLanguageTag(localeID).getName();
            if (tmpLocaleID.length() == 0) {
                tmpLocaleID = localeID;
            }
        } else {
            tmpLocaleID = localeID;
        }
        return nameCache.getInstance(tmpLocaleID, null /* unused */);
    }
516287
public function getPackageStats(Package $package, $localeID)
    {
        return $this->getMoFileStats($package->getPackagePath() . '/' . DIRNAME_LANGUAGES . '/' . $localeID . '/LC_MESSAGES/messages.mo');
    }
960907
public static String getLocaleFromId(String entityId) {

        if (entityId.startsWith(ENTITY_ID_PREFIX)) {
            return entityId.substring(ENTITY_ID_PREFIX.length(), entityId.lastIndexOf("/"));
        }
        return null;
    }
1061156
public function uri($locale = null)
    {
        $uri = $this->page->uri($locale).'#'.$this->position.'-'.$this->translate('slug', $locale);

        return $uri;
    }
2168
public function lookUpLanguageIdForLocale($locale)
    {
        $locale = $this->normalizeLocale($locale);

        /** @var Model $languageModel */
        $languageModel = static::$cmsLanguageModel;

        $language = $languageModel::where(config('pxlcms.translatable.locale_code_column'), $locale)
            ->remember((config('pxlcms.cache.languages', 15)))
            ->first();

        if (empty($language)) return null;

        return $language->id;
    }
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);
    }
654294
public static String canonicalize(String localeID){
        LocaleIDParser parser = new LocaleIDParser(localeID, true);
        String baseName = parser.getBaseName();
        boolean foundVariant = false;

        // formerly, we always set to en_US_POSIX if the basename was empty, but
        // now we require that the entire id be empty, so that "@foo=bar"
        // will pass through unchanged.
        // {dlf} I'd rather keep "" unchanged.
        if (localeID.equals("")) {
            return "";
            //              return "en_US_POSIX";
        }

        // we have an ID in the form xx_Yyyy_ZZ_KKKKK

        initCANONICALIZE_MAP();

        /* convert the variants to appropriate ID */
        for (int i = 0; i < variantsToKeywords.length; i++) {
            String[] vals = variantsToKeywords[i];
            int idx = baseName.lastIndexOf("_" + vals[0]);
            if (idx > -1) {
                foundVariant = true;

                baseName = baseName.substring(0, idx);
                if (baseName.endsWith("_")) {
                    baseName = baseName.substring(0, --idx);
                }
                parser.setBaseName(baseName);
                parser.defaultKeywordValue(vals[1], vals[2]);
                break;
            }
        }

        /* See if this is an already known locale */
        for (int i = 0; i < CANONICALIZE_MAP.length; i++) {
            if (CANONICALIZE_MAP[i][0].equals(baseName)) {
                foundVariant = true;

                String[] vals = CANONICALIZE_MAP[i];
                parser.setBaseName(vals[1]);
                if (vals[2] != null) {
                    parser.defaultKeywordValue(vals[2], vals[3]);
                }
                break;
            }
        }

        /* total mondo hack for Norwegian, fortunately the main NY case is handled earlier */
        if (!foundVariant) {
            if (parser.getLanguage().equals("nb") && parser.getVariant().equals("NY")) {
                parser.setBaseName(lscvToID("nn", parser.getScript(), parser.getCountry(), null));
            }
        }

        return parser.getName();
    }
1005530
private function checkExistingLocale($localeID)
    {
        $result = null;
        $localeRepo = $this->app->make(LocaleRepository::class);
        $existing = $localeRepo->find($localeID);
        if ($existing !== null) {
            if ($existing->isSource()) {
                $result = t("There couldn't be a language team for '%s' since it's the source language", $existing->getDisplayName());
            } elseif ($existing->isApproved()) {
                $result = t("The language team for '%s' already exists", $existing->getDisplayName());
            } elseif ($existing->getRequestedOn() !== null) {
                $result = t(
                    "The language team for '%1\$s' has already been requested on %2\$s",
                    $existing->getDisplayName(),
                    $this->app->make('date')->formatDateTime($existing->getRequestedOn(), true)
                );
            } else {
                $result = t("The language team for '%s' has already been requested", $existing->getDisplayName());
            }
        }

        return $result;
    }
995249
private function getPath($resourceId = null)
    {
        if (!is_null($resourceId)) {
            $endpoint = ($this->isOrder($resourceId) ? Orders::PATH : Payment::PATH);

            return sprintf('/%s/%s/%s/%s', MoipResource::VERSION, $endpoint, $resourceId, self::PATH);
        }

        if ($this->order !== null) {
            return sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Orders::PATH, $this->order->getId(), self::PATH);
        }

        return sprintf('/%s/%s/%s/%s', MoipResource::VERSION, Payment::PATH, $this->payment->getId(), self::PATH);
    }