Match an language code with the aviable languages

CCLang::parse( 'de' );
CCLang::parse( 'EN-US' );
CCLang::parse( 'de-DE,en,fr' );

@param string    $lang
@return string
339229
public static function parse( $lang ) 
	{
		$conf = ClanCats::$config->language;
		
		if ( isset( $lang ) && strlen( $lang ) > 1 ) 
		{
			$lang = explode( ',', strtolower( $lang ) );
			$lang = explode( '-', $lang[0] );
			
			if ( !isset( $lang[1] ) ) 
			{
				$lang[1] = $lang[0];
			}
			
			$available = $conf['available'];
			
			if ( array_key_exists( $lang[0], $available ) ) 
			{
				// does even the region match?
				if ( in_array( $lang[1], $available[$lang[0]] ) ) 
				{
					return $lang[0].'-'.$lang[1];
				}
				// return the first region
				else 
				{
					$locales = $available[$lang[0]];
					return $lang[0].'-'.$locales[key($locales)];
				}
			}
		}
		
		// Return the default language when nothing coul be matched
		return $conf['default'];
	}
671288
public function setLanguage($lang)
	{
		$this->lang     = $lang;
		$this->metadata = $this->getMetadata($this->lang);

		return $this;
	}
723994
public static function set_current( $lang ) 
	{
		$lang = static::parse( $lang );
		
		if ( !array_key_exists( $lang, static::$data ) ) 
		{
			static::$data[$lang] = array();
		}
		
		return static::$current_language = $lang;
	}
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 ) );
	}
719941
public static function getMessage( $code, $lang = 'EN' ) {
    if( $code < 0 ) {
      return null;
    } //code invalid

    $lang = strtoupper( $lang );

    if( !array_key_exists( $lang, self::$code ) ) { //language not found
      $lang = 'EN';
    }

    if( array_key_exists( $code, self::$code[$lang] ) ) { //code not defined
      return self::$code[$lang][$code];
    }

    return null;
  }
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;
	}
617394
public static function getLang($language)
    {
        $pos = strpos($language, '-');
        return $pos > 0 ? substr($language, 0, $pos) : $language;
    }
747809
public function set($lang) {
    if (!array_key_exists($lang, $this->getList())) {
      throw new LanguageNotPresentException;
    }
    $this->locator->set($lang);
    return $lang;
  }
537260
public function getSinglelangFields($table, $lang)
    {
        $langTable = getLangTableName($table, $lang);

        $baseFields = $this->getFields($table);
        $langFields = $this->getFields($langTable);

        //Some fields (for example OXID) must be taken from core table.
        $langFields = $this->filterCoreFields($langFields);

        $fields = array_merge($baseFields, $langFields);
        $singleLangFields = [];

        foreach ($fields as $fieldName => $field) {
            if (preg_match("/(({$table}|{$langTable})\.)?(?<field>.+)_(?<lang>[0-9]+)$/", $field, $matches)) {
                if ($matches['lang'] == $lang) {
                    $singleLangFields[$matches['field']] = $field;
                }
            } else {
                $singleLangFields[$fieldName] = $field;
            }
        }

        return $singleLangFields;
    }
1371321
public function getOptionsByLang($lang = 'en')
    {
        $finalOptions = [];

        foreach ($this->getOptions() as $options) {
            foreach ($options as $option) {
                if ($option->lang == $lang || $option->isPlain) {
                    $finalOptions[] = $option;
                }
            }
        }

        return empty($finalOptions) ? null : $finalOptions;
    }
270705
public function getRegularLangName($lang = NULL) {
        if (isset($this->_data['env']['APP_LANG_NAME'])) {
            return $this->_data['env']['APP_LANG_NAME'];
        }

        if (is_null($lang))
            $lang = Yii::$app->language;
        $this->_data['env']['ENABLED_LANGS'] = str_replace("-", "_", strtolower($lang));

        return $this->_data['env']['ENABLED_LANGS'];
    }
1044921
public function alias($lang, $aliases)
    {
        $lang = strtolower($lang);

        if (!is_array($aliases)) {
            $aliases = [$aliases];
        }

        $aliases = array_map('strtolower', $aliases);

        $this->aliases[$lang] = array_unique(
            array_merge(Arr::get($this->aliases, $lang, []), $aliases)
        );

        return $this;
    }
139631
public function getL10n($lang = null) {
		if (is_null($lang)) $lang = $this->_language;

		$file = $this->_language_path . $lang . '/l10n.php';
		return $this->_loadFile($file, true);
	}
1311210
public static function loadLang($lang)
	{
		$list = array ();
		// 框架语言包
		$file = ROOT_PATH . Config::get('@.LANG_PATH') . '/' . $lang . '.lang.php';
		if (is_file($file))
		{
			$data = include $file;
			$list = array_merge($list, $data);
		}
		// 项目语言包
		$file = APP_LANG . $lang . '.lang.php';
		if (is_file($file))
		{
			$data = include $file;
			$list = array_merge($list, $data);
		}
		// 获取模块名
		$m = Dispatch::module();
		// 是否开启模块
		if ('' !== $m)
		{
			// 模块语言包
			$file = APP_MODULE . $m . '/' . Config::get('@.LANG_PATH') . '/'. $lang .'.lang.php';
			if (is_file($file))
			{
				$data = include $file;
				$list = array_merge($list, $data);
			}
		}
		return $list;
	}
1041707
public function getCustomerLang()
    {
        $lang = $this->getLangModel();

        if ($lang === null) {
            $lang = (new LangQuery)
                ->filterByByDefault(1)
                ->findOne()
            ;
        }

        return $lang;
    }
1064663
function versionName( $lang = false )
    {
        if ( !$lang )
        {
            $lang = $this->initialLanguageCode();
        }

        if ( isset( $this->VersionNameCache[$lang] ) )
            return $this->VersionNameCache[$lang];

        $object = $this->attribute( 'contentobject' );
        if ( !$object )
        {
            $retValue = false;
            return $retValue;
        }

        $class = $object->attribute( 'content_class' );
        if ( !$class )
        {
            $retValue = false;
            return $retValue;
        }

        $this->VersionNameCache[$lang] = $class->contentObjectName( $object,
                                                                    $this->attribute( 'version' ),
                                                                    $lang );
        return $this->VersionNameCache[$lang];
    }
53205
public function setLang( $lang ) {
		if ( !IntuitionUtil::nonEmptyStr( $lang ) ) {
			return false;
		}
		$this->currentLanguage = $this->normalizeLang( $lang );
		return true;
	}