Splits language code and return itself and all its 'super-languages' (less specific langs).
Caches the results locally so it doesn't have to do it on every translation request.

@param   string  $lang
@return  array
438178
protected function split_lang($lang)
	{
		if ( ! isset($this->_fallback_paths[$lang]))
		{
			$splits = array();
			$lang_parts = explode('-', $lang);
			while ($lang_parts)
			{
				$splits[] = implode('-', $lang_parts);
				array_pop($lang_parts);
			}
			$this->_fallback_paths[$lang] = $splits;
		}
		return $this->_fallback_paths[$lang];
	}
895320
public function uninstall_language($lang) {
        global $CFG;

        $dest1 = $CFG->dataroot.'/lang/'.$lang;
        $dest2 = $CFG->dirroot.'/lang/'.$lang;
        $rm1 = false;
        $rm2 = false;
        if (file_exists($dest1)) {
            $rm1 = remove_dir($dest1);
        }
        if (file_exists($dest2)) {
            $rm2 = remove_dir($dest2);
        }

        if ($rm1 or $rm2) {
            $this->info[] = get_string('langpackremoved', 'tool_langimport', $lang);
            event\langpack_removed::event_with_langcode($lang)->trigger();
            return true;
        } else {    // Nothing deleted, possibly due to permission error.
            $this->errors[] = get_string('langpacknotremoved', 'tool_langimport', $lang);
            return false;
        }
    }
78103
public function getLangName( $lang = false ) {
		$lang = $lang ? $this->normalizeLang( $lang ) : $this->getLang();
		return $this->getLangNames()[$lang] ?? '';
	}
978277
public static function lang($lang = null)
    {
        if ($lang)
        {
            self::$lang = strtolower(str_replace(self::$_langNormalizeSearch, self::$_langNormalizeReplace, $lang));
        }
        return self::$lang;
    }
168409
public function out($lang = null) {
        if ($lang !== null && $lang != $this->lang && ($this->lang == null && $lang != current_language())) {
            if ($this->forcedstring) {
                debugging('lang_string objects that have been used cannot be printed in another language. ('.$this->lang.' used)', DEBUG_DEVELOPER);
                return $this->get_string();
            }
            $translatedstring = new lang_string($this->identifier, $this->component, $this->a, $lang);
            return $translatedstring->out();
        }
        return $this->get_string();
    }
246571
protected static function langSpecificCharsArray($language = 'en')
	{
		trigger_error('Function ' . __METHOD__ . ' not implemented yet');

		$split = preg_split('/[-_]/', $language);
		$language = strtolower($split[0]);

		static $charsArray = [];
		if (isset($charsArray[$language])) {
			return $charsArray[$language];
		}

		$languageSpecific = [
			'de' => [
				['ä',  'ö',  'ü',  'Ä',  'Ö',  'Ü' ],
				['ae', 'oe', 'ue', 'AE', 'OE', 'UE'],
			],
			'bg' => [
				['х', 'Х', 'щ', 'Щ', 'ъ', 'Ъ', 'ь', 'Ь'],
				['h', 'H', 'sht', 'SHT', 'a', 'А', 'y', 'Y']
			]
		];

		if (isset($languageSpecific[$language])) {
			$charsArray[$language] = $languageSpecific[$language];
		} else {
			$charsArray[$language] = [];
		}

		return $charsArray[$language];
	}
147434
public function getLanguage($language)
    {
        if (!$this->getLanguages()->has($language)) {
            $this->getLanguages()->set($language, new LanguageBag());
        }

        return $this->getLanguages()->get($language);
    }
27541
public function getLocalization($localization)
    {
        $localizations = $this->getLocalizations();
        if (!empty($localizations)) {
            foreach ($localizations as $webspaceLocalization) {
                $result = $webspaceLocalization->findLocalization($localization);

                if ($result) {
                    return $result;
                }
            }
        }

        return;
    }
1133108
public function isAvailableLanguage($lang)
    {
        return array_key_exists($lang, $this->getLoader()->getOption('available_languages')) ||
            in_array($lang, $this->getLoader()->getOption('available_languages'));
    }
261791
public function translationData($lang)
    {
        $translation = $this->translation($lang);

        if ($translation) {
            $data = json_decode($translation->entity_data);

            if (isset($data->blocks)) {
                $data->blocks = json_decode($data->blocks, true);
            }

            return $data;
        }

        return null;
    }
1288285
public function getUserGroups($lang = "")
    {
        // check if user has permissions to access this link
        if(!User::hasAccess('Permissions', 'read')) {
            return $this->noPermission();
        }
        return array('data' => \App\Models\UserGroup::all());
    }
573790
public function getLocale( $lang = null, $utf8 = true ) {
		$suffixes = $utf8 ? [ '.UTF-8', '.UTF-8', '.utf8' ] : [ '' ];
		$normal = isset( $lang ) ? $lang : $this->getLang();
		$normalUC = strtoupper( $normal );

		// Get 'foo' from 'foo-bar'
		$parts = explode( '-', $normal );
		$short = $parts[0];
		$shortUC = strtoupper( $short );

		$versions = [
			// foo-br or en
			$normal,
			// FOO-BR or EN
			$normalUC,
			// foo_FOO or en_EN
			$short . '_' . $shortUC,
			// foo or en
			$short,
			// FOO or EN
			$shortUC,
		];
		$return = [];
		foreach ( $versions as $version ) {
			foreach ( $suffixes as $suffix ) {
				$return[] = $version . $suffix;
			}
		}
		return array_values( array_unique( $return ) );
	}
1344675
private function extractDataOfLanguage($lang)
    {
        $found = [];
        // parsing language preference instructions
        // 2_digit_code[-longer_code][;q=coefficient]
        preg_match('/([a-z]{1,2})(-([a-z0-9]+))?(;q=([0-9\.]+))?/', $lang, $found);
        // 2 digit lang code
        $code = isset($found[1]) ? $found[1] : null;
        // lang code complement
        $morecode = isset($found[3]) ? $found[3] : null;
        // full lang code
        $fullcode = $morecode ? $code.'-'.$morecode : $code;
        // coefficient
        $coef = sprintf('%3.1f', isset($found[5]) ? $found[5] : '1');
        // for sorting by coefficient
        // adding
        return array('code' => $code,'coef' => $coef,'morecode' => $morecode,'fullcode' => $fullcode);
    }
1032439
public static function getMetadata($lang)
	{
		$path = self::getLanguagePath(PATH_APP . DS . 'bootstrap' . DS . \App::get('client')->name, $lang);
		$file = $lang . '.xml';

		$result = null;

		if (!is_file("$path/$file"))
		{
			$path = self::getLanguagePath(PATH_CORE . DS . 'bootstrap' . DS . ucfirst(\App::get('client')->name), $lang);
		}

		if (is_file("$path/$file"))
		{
			$result = self::parseXMLLanguageFile("$path/$file");
		}

		if (empty($result))
		{
			return null;
		}

		return $result;
	}
54386
public function get_list_of_currencies($lang = null) {
        if ($lang === null) {
            $lang = current_language();
        }

        $currencies = $this->load_component_strings('core_currencies', $lang);
        asort($currencies);

        return $currencies;
    }
685127
public function filterLanguage($language)
    {
        $countries = array();
        foreach ($this->countries as $country) {
            if ($country->getLanguages()->contains($language)) {
                $countries[] = $country;
            }
        }

        return new self($countries);
    }
702414
protected function plural_rules($lang)
	{
		if ( ! isset($this->_rules[$lang]))
		{
			// Get language code prefix
			$parts = explode('-', $lang, 2);
			$this->_rules[$lang] = $this->plural_rules_factory()
				->create_rules($parts[0]);
		}
		return $this->_rules[$lang];
	}