<?php
/* versionbeta:name
 * versionbeta:number
 * versionbeta:site
 * versionbeta:pubtime
 */
class cls_language{
	static $perms = array();
	static function get($msg_name,$msg_type="sys"){
		if( !isset(self::$perms[$msg_type]) ) {
			self::on_load($msg_type);
		}
		if( isset( self::$perms[$msg_type][$msg_name] ) ) {
			$arr = self::$perms[$msg_type][$msg_name];
			$arrx = $arr;
			if(is_array($arr)) {
				foreach($arr as $item=>$key) {
					$arrx[$item] = tab_other_language::get($key);
				}
			} else {
				$arrx = tab_other_language::get($arr);
			}
			return $arrx;
		} else {
			$arr = explode("_" , $msg_name);
			if(count($arr)>1) {
				$arr_x = array();
				foreach($arr as $item) {
					$arr_x[] = self::get($item , $msg_type);
				}
				$msg_name = implode("" , $arr_x);
			} else {
				foreach(self::$perms as $item) {
					if(isset($item[$msg_name])) return $item[$msg_name];
				}
			}
			return $msg_name;
		}
	}
	static function on_load($msg_type) {
		$str_lang = cls_config::get_env("language");
		//$str_lang = cls_obj::get("cls_session")->get_env("language");
		if( empty( $str_lang ) ) {
			$str_lang = cls_config::DEFAULT_LANGUAGE;
		}
		self::$perms[$msg_type] = include( KJ_DIR_DATA."/language/".$str_lang."/".$msg_type.".php" );
	}
}