Parse list of comma separated language tags and sort it by the
quality value from `$this->globalServer['HTTP_ACCEPT_LANGUAGE']`.
@param string[] $languagesList
@return array
487473
public static function ParseHttpAcceptLang ($languagesList) {
		$languages = [];
		$languageRanges = explode(',', trim($languagesList));
		foreach ($languageRanges as $languageRange) {
			$regExpResult = preg_match(
				"/(\*|[a-zA-Z0-9]{1,8}(?:-[a-zA-Z0-9]{1,8})*)(?:\s*;\s*q\s*=\s*(0(?:\.\d{0,3})|1(?:\.0{0,3})))?/",
				trim($languageRange),
				$match
			);
			if ($regExpResult) {
				$priority = isset($match[2])
					? (string) floatval($match[2])
					: '1.0';
				if (!isset($languages[$priority])) $languages[$priority] = [];
				$langOrLangWithLocale = str_replace('-', '_', $match[1]);
				$delimiterPos = strpos($langOrLangWithLocale, '_');
				if ($delimiterPos !== FALSE) {
					$languages[$priority][] = [
						strtolower(substr($langOrLangWithLocale, 0, $delimiterPos)),
						strtoupper(substr($langOrLangWithLocale, $delimiterPos + 1))
					];
				} else {
					$languages[$priority][] = [
						strtolower($langOrLangWithLocale),
						NULL
					];
				}
			}
		}
		krsort($languages);
		reset($languages);
		return $languages;
	}
1227969
public function getTranslations(
        array $domains = [],
        array $languages = [],
        callable $filter = null
    ) : array {
        $translations = array_filter(
            $this->translations,
            function (Translation $translation) {
                return $translation->getValue() != '';
            }
        );

        if (is_callable($filter)) {
            $translations = array_filter(
                $translations,
                $filter
            );
        }

        return $translations;
    }
817404
public function getLanguages()
    {
        $source = $this->server['HTTP_ACCEPT_LANGUAGE'];

        if (strpos($source, ',') !== false) {
            $langs = explode(',', $source);
            return $langs;
        } else {
            return array($source);
        }
    }
992973
function untranslatedLanguages()
    {
        $availableLanguages = $this->prioritizedLanguages();
        $availableLanguagesCodes = array_keys( $availableLanguages );

        $languages = array();
        foreach ( eZContentLanguage::prioritizedLanguages() as $language )
        {
            $languageCode = $language->attribute( 'locale' );
            if ( !in_array( $languageCode, $availableLanguagesCodes ) )
            {
                $languages[$languageCode] = $language;
            }
        }

        return $languages;
    }
736576
private function getCountriesForLanguage($languageID)
    {
        $cl = $this->app->make('lists/countries');
        $recommendedCountries = [];
        foreach ($cl->getCountriesForLanguage($languageID) as $countryID) {
            $recommendedCountries[$countryID] = $cl->getCountryName($countryID);
        }
        $otherCountries = [];
        foreach ($cl->getCountries() as $countryID => $countryName) {
            if (!isset($recommendedCountries[$countryID])) {
                $otherCountries[$countryID] = $countryName;
            }
        }
        if (count($recommendedCountries) === 0) {
            $result = $otherCountries;
        } elseif (count($otherCountries) === 0) {
            $result = $recommendedCountries;
        } else {
            $result = [
                t('** Recommended Countries') => $recommendedCountries,
                t('** Other Countries') => $otherCountries,
            ];
        }

        return $result;
    }
452074
public function getAcceptableLanguages()
    {
        if ($this->_languages === null) {
            if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
                $this->_languages = array_keys(static::parseAcceptHeader($_SERVER['HTTP_ACCEPT_LANGUAGE']));
            } else {
                $this->_languages = [];
            }
        }

        return $this->_languages;
    }
1107804
public function language($langs)
    {
        //force array
        settype($langs, 'array');

        $scripts = '';
        $language = $this->getService('anahita:language');
        $tag = $language->getTag();
        $base = $language->getLanguagePath(ANPATH_ROOT, $tag);

        foreach ($langs as $lang) {
            $path = $base.'/'.$tag.'.'.$lang.'.js';
            if (is_readable($path)) {
                $src = AnService::get('com:application')->getRouter()->getBaseUrl().'/language/'.$tag.'/'.$tag.'.'.$lang.'.js';
                $scripts .= '<script type="text/javascript" src="'.$src.'"></script>'."\n";
            }
        }

        return  $scripts;
    }
947219
public function parseTranslatableList(array $listElement)
    {
        $listItems = array();
        foreach ($listElement['value'] as $valueRow) {
            $listItems[$valueRow['_languageCode']] = isset($valueRow['#text']) ?
                $valueRow['#text'] :
                '';
        }

        return $listItems;
    }
1249299
private function extractLanguageCodesFromSolrResult( $solrResults )
    {
        $languages = array();

        if ( isset( $solrResults['response']['docs'] ) )
        {
            foreach ( $solrResults['response']['docs'] as $doc )
            {
                if ( isset( $doc['meta_language_code_ms'] ) )
                {
                    $languages[] = $doc['meta_language_code_ms'];
                }
            }
        }

        return $languages;
    }
764720
public function hasLanguageValues($values)
    {
        $tagValues = $this->getLanguageValues(true);
        foreach ($this->filterLanguageValues($values) as $value) {
            if (!in_array($value, $tagValues)) {
                return false;
            }
        }
        return true;
    }
564625
protected function getListLanguage($count = false)
    {
        $list = $this->language->getList();

        $allowed = $this->getAllowedFiltersLanguage();
        $this->filterList($list, $allowed, $this->query_filter);
        $this->sortList($list, $allowed, $this->query_filter, array('code' => 'asc'));

        if ($count) {
            return count($list);
        }

        $this->limitList($list, $this->data_limit);
        $this->prepareListLanguage($list);
        return $list;
    }
871696
protected function parseTags($tags) {
		$tags = trim($tags);
		if (!empty($tags)) {
			
			// sanitize lines
			$result = [];
			foreach (explode("\n", $tags) as $line) {
				if ($this->isTagLine($line) || count($result) == 0) {
					$result[] = $line;
				} else {
					$result[count($result) - 1] .= PHP_EOL . $line;
				}
			}

			// create proper Tag objects
			if (count($result)) {
				$this->tags->clear();
				foreach ($result as $line) {
					$this->tags->add($this->parseTag($line)); 
				}
			}
		}
		
		
	}
379430
public static function languagesLocaleCodes()
    {
        static $list;

        if ($list === null) {
            $list = [];
            foreach (static::codes() as $localeCode) {
                if ($languageCode = static::languageCode($localeCode)) {
                    $list[$languageCode][] = $localeCode;
                }
            }
        }

        return $list;
    }
1270259
public function groupTranslations($results)
    {
        return $results->map(function ($row) {
            if (!$row instanceof EntityInterface) {
                return $row;
            }
            $translations = (array)$row->get('_i18n');
            if (empty($translations) && $row->get('_translations')) {
                return $row;
            }
            $grouped = new Collection($translations);

            $result = [];
            foreach ($grouped->combine('field', 'content', 'locale') as $locale => $keys) {
                $entityClass = $this->_table->getEntityClass();
                $translation = new $entityClass($keys + ['locale' => $locale], [
                    'markNew' => false,
                    'useSetters' => false,
                    'markClean' => true
                ]);
                $result[$locale] = $translation;
            }

            $options = ['setter' => false, 'guard' => false];
            $row->set('_translations', $result, $options);
            unset($row['_i18n']);
            $row->clean();

            return $row;
        });
    }
1060705
private function parse($tokens, ?TypeContext $context = null): array
    {
        $count = count($tokens);
        $tagCount = 0;
        $tags = [];

        for ($i = 1; $i < $count; $i += 2) {
            $tags[] = $this->tagFactory->create($tokens[$i], $context);
            $tokens[$i] = '%' . ++$tagCount . '$s';
        }

        //In order to allow "literal" inline tags, the otherwise invalid
        //sequence "{@}" is changed to "@", and "{}" is changed to "}".
        //"%" is escaped to "%%" because of vsprintf.
        //See unit tests for examples.
        for ($i = 0; $i < $count; $i += 2) {
            $tokens[$i] = str_replace(['{@}', '{}', '%'], ['@', '}', '%%'], $tokens[$i]);
        }

        return [implode('', $tokens), $tags];
    }
697036
public function getVoteLanguages($mode = null)
    {
        arsort($this->votes, SORT_NUMERIC);

        if (self::VOTED_HIGH === $mode) {
            if (!count($this->votes)) {
                return $this->votes;
            }

            $languages = array();

            // Get first item
            list ($language, $highVote) = each($this->votes);
            $languages[] = $language;

            while ($item = each($this->votes)) {
                list ($language, $votes) = $item;
                if ($highVote === $votes) {
                    $languages[] = $language;
                } else {
                    break;
                }
            }

            return $languages;

        }

        return $this->votes;
    }
1368650
public function getLanguageValues($asArray = null)
    {
        if (!$this->owner->getIsNewRecord() && $this->_languageValues === null) {
            $this->_languageValues = [];

            /* @var ActiveRecord $language */
            foreach ($this->owner->{$this->languageRelation} as $language) {
                $this->_languageValues[] = $language->getAttribute($this->languageValueAttribute);
            }
        }

        if ($asArray === null) {
            $asArray = $this->languageValuesAsArray;
        }

        if ($asArray) {
            return $this->_languageValues === null ? [] : $this->_languageValues;
        } else {
            return $this->_languageValues === null ? '' : implode(', ', $this->_languageValues);
        }
    }