mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-30 15:52:17 +09:00
Initial implementation of lang class that prefers PHP to XML
This commit is contained in:
parent
8ae2dba0b9
commit
f68e6118bc
3 changed files with 219 additions and 132 deletions
|
|
@ -337,8 +337,10 @@ class Context
|
|||
self::set('lang_supported', $lang_supported);
|
||||
self::setLangType($this->lang_type);
|
||||
|
||||
// load module module's language file according to language setting
|
||||
self::loadLang(_XE_PATH_ . 'modules/module/lang');
|
||||
// Load languages
|
||||
$this->lang = Rhymix\Framework\Lang::getInstance($this->lang_type);
|
||||
$this->lang->addDirectory(RX_BASEDIR . 'common/lang');
|
||||
$this->lang->addDirectory(RX_BASEDIR . 'modules/module/lang');
|
||||
|
||||
// set session handler
|
||||
if(self::isInstalled() && $this->db_info->use_db_session == 'Y')
|
||||
|
|
@ -405,9 +407,6 @@ class Context
|
|||
}
|
||||
}
|
||||
|
||||
// load common language file
|
||||
self::loadLang(_XE_PATH_ . 'common/lang/');
|
||||
|
||||
// check if using rewrite module
|
||||
$this->allow_rewrite = ($this->db_info->use_rewrite == 'Y' ? TRUE : FALSE);
|
||||
|
||||
|
|
@ -920,118 +919,7 @@ class Context
|
|||
*/
|
||||
public static function loadLang($path)
|
||||
{
|
||||
global $lang;
|
||||
|
||||
if(!self::$_instance->lang_type)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(!is_object($lang))
|
||||
{
|
||||
$lang = new stdClass;
|
||||
}
|
||||
|
||||
if(!($filename = self::$_instance->_loadXmlLang($path)))
|
||||
{
|
||||
$filename = self::$_instance->_loadPhpLang($path);
|
||||
}
|
||||
|
||||
if(!is_array(self::$_instance->loaded_lang_files))
|
||||
{
|
||||
self::$_instance->loaded_lang_files = array();
|
||||
}
|
||||
if(in_array($filename, self::$_instance->loaded_lang_files))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if($filename && is_readable($filename))
|
||||
{
|
||||
self::$_instance->loaded_lang_files[] = $filename;
|
||||
include($filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
self::$_instance->_evalxmlLang($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Evaluation of xml language file
|
||||
*
|
||||
* @param string Path of the language file
|
||||
* @return void
|
||||
*/
|
||||
public function _evalxmlLang($path)
|
||||
{
|
||||
global $lang;
|
||||
|
||||
if(!$path) return;
|
||||
|
||||
$_path = 'eval://' . $path;
|
||||
|
||||
if(in_array($_path, $this->loaded_lang_files))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if(substr_compare($path, '/', -1) !== 0)
|
||||
{
|
||||
$path .= '/';
|
||||
}
|
||||
|
||||
$oXmlLangParser = new XmlLangParser($path . 'lang.xml', $this->lang_type);
|
||||
$content = $oXmlLangParser->getCompileContent();
|
||||
|
||||
if($content)
|
||||
{
|
||||
$this->loaded_lang_files[] = $_path;
|
||||
eval($content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load language file of xml type
|
||||
*
|
||||
* @param string $path Path of the language file
|
||||
* @return string file name
|
||||
*/
|
||||
public function _loadXmlLang($path)
|
||||
{
|
||||
if(!$path) return;
|
||||
|
||||
$oXmlLangParser = new XmlLangParser($path . ((substr_compare($path, '/', -1) !== 0) ? '/' : '') . 'lang.xml', $this->lang_type);
|
||||
return $oXmlLangParser->compile();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load language file of php type
|
||||
*
|
||||
* @param string $path Path of the language file
|
||||
* @return string file name
|
||||
*/
|
||||
public function _loadPhpLang($path)
|
||||
{
|
||||
if(!$path) return;
|
||||
|
||||
if(substr_compare($path, '/', -1) !== 0)
|
||||
{
|
||||
$path .= '/';
|
||||
}
|
||||
$path_tpl = $path . '%s.lang.php';
|
||||
$file = sprintf($path_tpl, $this->lang_type);
|
||||
|
||||
$langs = array('ko', 'en'); // this will be configurable.
|
||||
while(!is_readable($file) && $langs[0])
|
||||
{
|
||||
$file = sprintf($path_tpl, array_shift($langs));
|
||||
}
|
||||
|
||||
if(!is_readable($file))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
return $file;
|
||||
return self::$_instance->lang->addDirectory($path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1069,15 +957,8 @@ class Context
|
|||
*/
|
||||
public static function getLang($code)
|
||||
{
|
||||
if(!$code)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if($GLOBALS['lang']->{$code})
|
||||
{
|
||||
return $GLOBALS['lang']->{$code};
|
||||
}
|
||||
return $code;
|
||||
$lang = self::$_instance->lang;
|
||||
return isset($lang->{$code}) ? $lang->{$code} : $code;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1089,11 +970,7 @@ class Context
|
|||
*/
|
||||
public static function setLang($code, $val)
|
||||
{
|
||||
if(!isset($GLOBALS['lang']))
|
||||
{
|
||||
$GLOBALS['lang'] = new stdClass;
|
||||
}
|
||||
$GLOBALS['lang']->{$code} = $val;
|
||||
self::$_instance->lang->{$code} = $val;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue