/*!
The same as 'languageLocaleList' but returns a list of 'eZContentLanguage' objects.

\return array of language objects.
550285
function languages()
    {
        $languages = array();

        $languageLocaleList = $this->languageLocaleList();
        foreach( $languageLocaleList as $languageLocale )
            $languages[$languageLocale] = eZContentLanguage::fetchByLocale( $languageLocale );

        return $languages;
    }
224387
public List<ULocale> getLocales() {
        List<ULocale> result;
        if (locales == null) {
            result = guessLocales();
        } else {
            result = new ArrayList<ULocale>();
            result.addAll(locales);
        }
        return result;
    }
1257574
public function setupLanguages(): Collection
    {
        return $this->coreModules()
            ->filter(static function (ModuleInterface $module) {
                return $module instanceof ModuleLanguageInterface && $module->isEnabledByDefault();
            })
            ->sort(static function (ModuleLanguageInterface $x, ModuleLanguageInterface $y) {
                return $x->locale()->endonymSortable() <=> $y->locale()->endonymSortable();
            });
    }
996414
public function getSupportedLocales()
    {
        $return = [];
        $process = new Process(['locale', '-a']);
        $process->run();
        $installedLocales = explode(PHP_EOL, trim($process->getOutput()));
        foreach ($this->supportedLocales as $supportedLocale) {
            if (in_array($supportedLocale, $installedLocales)
                || in_array($supportedLocale.'.utf8', $installedLocales)
            ) {
                $return[] = new Locale($supportedLocale);
            }
        }

        return $return;
    }
1311998
private List<Locale> extractLocales(List<List<String>> allLangs) {
        List<Locale> rc = new ArrayList<Locale>();
        for (List<String> langList : allLangs) {
            for (String language : langList) {
                String country = "";
                String variant = "";
                int countryIndex = language.indexOf('-');
                if (countryIndex > -1) {
                    int variantIndex = language.indexOf('-', (countryIndex + 1));
                    if (variantIndex > -1) {
                        variant = language.substring(variantIndex + 1).trim();
                        country = language.substring(countryIndex, variantIndex).trim();
                    } else {
                        country = language.substring(countryIndex + 1).trim();
                    }
                    language = language.substring(0, countryIndex).trim();
                }

                rc.add(new Locale(language, country, variant));
            }
        }

        return rc;
    }
219638
public static function getAvailableLocalesInfo()
    {
        $languages = [];
        foreach (static::getAvailableLocales() as $id) {
            $languages[$id] = new Language($id);
        }

        return $languages;
    }
1008661
public function getBestRenderLocales($ordered = self::ORDER_LANG) {
        $locales = [];
        $this->getServerLocales();

        foreach($this->getClientLocales() as $locale) {
            /** @var Locale $locale  */

            $loc = $this->serverLocales->getBestMatchingLocaleForLocale($locale);
            if($loc && !in_array($loc, $locales)) {
                $locales[]  = $loc;
            }
        }
        if(count($locales) == 0) {
            if($this->defaultLocale)
                $locales[] = $this->defaultLocale;
            else {
                $locales[] = $this->getServerLocales()[0] ?? NULL;
            }
        }

        if($ordered & self::ORDER_STRUCT) {
            $locs = [];
            foreach($locales as $loc) {
                /** @var Locale $loc */
                $lang = $loc->getLanguage();

                $locs[$lang][] = $loc;
            }

            if($ordered & self::ORDER_LANG) {
                foreach($locs as &$ll)
                    usort($ll, LocaleCollection::LANG_SORT_CALLBACK);
            } elseif($ordered & self::ORDER_REG) {
                foreach($locs as &$ll)
                    usort($ll, LocaleCollection::REG_SORT_CALLBACK);
            }

            return $locs;
        }

        return $locales;
    }
1021056
public function loadLanguages()
    {
        $languages = $this->languageHandler->loadAll();

        $returnArray = array();
        foreach ($languages as $language) {
            $returnArray[] = $this->buildDomainObject($language);
        }

        return $returnArray;
    }
418653
private static Collection<Locale> getAllLocales() {

        Set<Locale> result = new HashSet<Locale>();
        result.addAll(OpenCms.getWorkplaceManager().getLocales());
        result.addAll(OpenCms.getLocaleManager().getAvailableLocales());
        return result;
    }
685229
public function loadAll()
    {
        $languages = $this->cache->get('ez-language-list');
        if ($languages === null) {
            $languages = $this->innerHandler->loadAll();
            $this->storeCache($languages, 'ez-language-list');
        }

        return $languages;
    }
706384
public function getDisplayLocales()
    {
        $locales = array();

        foreach ($this->allowedLocales as $locale) {
            $locales[$locale] = \Locale::getDisplayName($locale);
        }

        return $locales;
    }
666997
public function getSupportedLanguages(): array
    {
        if (null === $this->supportedLanguages) {
            $process = $this->createProcess('-D');
            $process->run();
            if (!$process->isSuccessful()) {
                throw new ExternalProgramFailedException(
                    $process->getCommandLine(),
                    $process->getErrorOutput(),
                    $process->getExitCode()
                );
            }

            $languages = [];

            $output = explode(PHP_EOL, $process->getErrorOutput());
            $is_win = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
            foreach ($output as $line) {
                $line = trim($line);
                if ('' === $line // Skip empty lines
                    || substr($line, -1) === ':' // Skip headers
                    || strpos($line, $is_win ? ';' : ':') !== false // Skip search path
                ) {
                    continue;
                }
                $name = basename($line);
                if (strpos($name, 'hyph_') === 0) {
                    // Skip MySpell hyphen files
                    continue;
                }
                $name = preg_replace('/\.(aff|dic)$/', '', $name);
                $languages[$name] = true;
            }

            $languages = array_keys($languages);
            sort($languages);
            $this->supportedLanguages = $languages;
        }

        return $this->supportedLanguages;
    }
1083045
protected function getLocaleChoices()
    {
        $localeChoices = [];

        if (!$this->request) {
            return [];
        }

        if (!$this->getRequest()->get('locale')) {
            $locale = $this->getRequest()->getLocale();
        } else {
            $locale = $this->getRequest()->get('locale');
        }

        if (is_array($locale) && array_key_exists('value', $locale)) {
            $locale = $locale['value'];
        }

        $localeList = Intl::getLocaleBundle()->getLocaleNames(substr($locale, 0, 2));

        foreach ($this->languages as $language) {
            $localeChoices[$localeList[$language['locale']]] = $language['locale'];
        }

        return $localeChoices;
    }
1259364
public function getLanguageArray($iLanguage = null, $blOnlyActive = false, $blSort = false)
    {
        $myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();

        if (is_null($iLanguage)) {
            $iLanguage = $this->_iBaseLanguageId;
        }

        $aLanguages = [];
        $aConfLanguages = $myConfig->getConfigParam('aLanguages');
        $aLangParams = $myConfig->getConfigParam('aLanguageParams');

        if (is_array($aConfLanguages)) {
            $i = 0;
            reset($aConfLanguages);
            foreach ($aConfLanguages as $key => $val) {
                if ($blOnlyActive && is_array($aLangParams)) {
                    //skipping non active languages
                    if (!$aLangParams[$key]['active']) {
                        $i++;
                        continue;
                    }
                }

                if ($val) {
                    $oLang = new stdClass();
                    $oLang->id = isset($aLangParams[$key]['baseId']) ? $aLangParams[$key]['baseId'] : $i;
                    $oLang->oxid = $key;
                    $oLang->abbr = $key;
                    $oLang->name = $val;

                    if (is_array($aLangParams)) {
                        $oLang->active = $aLangParams[$key]['active'];
                        $oLang->sort = $aLangParams[$key]['sort'];
                    }

                    $oLang->selected = (isset($iLanguage) && $oLang->id == $iLanguage) ? 1 : 0;
                    $aLanguages[$oLang->id] = $oLang;
                }
                ++$i;
            }
        }

        if ($blSort && is_array($aLangParams)) {
            uasort($aLanguages, [$this, '_sortLanguagesCallback']);
        }

        return $aLanguages;
    }
1070856
static function languageInfoFromPackageList( $packageNameList, $withLanguageNames = false )
    {
        $languageInfo = array();
        foreach( $packageNameList as $packageName )
        {
            $package = eZPackage::fetch( $packageName, false, false, false );
            if( is_object( $package ) )
            {
                $packageLanguageInfo = $package->languageInfo( $withLanguageNames );
                // merge arrays
                if( $withLanguageNames )
                {
                    // we have array like 'locale' => 'name'. can use array_merge
                    $languageInfo = array_merge( $languageInfo, $packageLanguageInfo );
                }
                else
                {
                    foreach( $packageLanguageInfo as $languageLocale )
                    {
                        if( !in_array( $languageLocale, $languageInfo ) )
                        {
                            $languageInfo[] = $languageLocale;
                        }
                    }
                }
            }
            else
            {
                eZDebug::writeWarning( "Unable to fetch package '$packageName'", __METHOD__ );
            }
        }

        return $languageInfo;
    }
426334
public function Locales()
    {
        $data = [];
        foreach (Locale::getCached() as $localeObj) {
            /** @var Locale $localeObj */
            $data[] = $this->owner->LocaleInformation($localeObj->getLocale());
        }
        return ArrayList::create($data);
    }
895256
public function fetchAll()
    {
        if (static::$languages === null) {
            static::$languages = $this->driver()->fetchAll();

            static::$languages = array_map(function ($language) {
                return new Locale($language);
            }, static::$languages);
        }

        return static::$languages;
    }