mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-05-09 20:12:14 +09:00
Fix unit tests, and auto-load default lang if not loaded
This commit is contained in:
parent
c67dbbc659
commit
1a3c500c76
2 changed files with 19 additions and 24 deletions
|
|
@ -859,7 +859,7 @@ class Context
|
||||||
* Load language file according to language type
|
* Load language file according to language type
|
||||||
*
|
*
|
||||||
* @param string $path Path of the language file
|
* @param string $path Path of the language file
|
||||||
* @return bool
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function loadLang($path)
|
public static function loadLang($path)
|
||||||
{
|
{
|
||||||
|
|
@ -872,15 +872,13 @@ class Context
|
||||||
$plugin_name = null;
|
$plugin_name = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
|
if (!$GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
|
||||||
{
|
{
|
||||||
|
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(self::$_instance->lang_type ?: config('locale.default_lang') ?: 'ko');
|
||||||
|
$GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
|
||||||
|
}
|
||||||
|
|
||||||
return $GLOBALS['lang']->loadDirectory($path, $plugin_name);
|
return $GLOBALS['lang']->loadDirectory($path, $plugin_name);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -923,34 +921,31 @@ class Context
|
||||||
*/
|
*/
|
||||||
public static function getLang($code)
|
public static function getLang($code)
|
||||||
{
|
{
|
||||||
if ($GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
|
if (!$GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
|
||||||
{
|
{
|
||||||
|
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(self::$_instance->lang_type ?: config('locale.default_lang') ?: 'ko');
|
||||||
|
$GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
|
||||||
|
}
|
||||||
|
|
||||||
return $GLOBALS['lang']->get($code);
|
return $GLOBALS['lang']->get($code);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return $code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set data to lang variable
|
* Set data to lang variable
|
||||||
*
|
*
|
||||||
* @param string $code Language variable name
|
* @param string $code Language variable name
|
||||||
* @param string $val `$code`s value
|
* @param string $val `$code`s value
|
||||||
* @return bool
|
* @return void
|
||||||
*/
|
*/
|
||||||
public static function setLang($code, $val)
|
public static function setLang($code, $val)
|
||||||
{
|
{
|
||||||
if ($GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
|
if (!$GLOBALS['lang'] instanceof Rhymix\Framework\Lang)
|
||||||
{
|
{
|
||||||
|
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance(self::$_instance->lang_type ?: config('locale.default_lang') ?: 'ko');
|
||||||
|
$GLOBALS['lang']->loadDirectory(RX_BASEDIR . 'common/lang', 'common');
|
||||||
|
}
|
||||||
|
|
||||||
$GLOBALS['lang']->set($code, $val);
|
$GLOBALS['lang']->set($code, $val);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,8 @@ class DateTimeTest extends \Codeception\TestCase\Test
|
||||||
|
|
||||||
public function testGetTimeGap()
|
public function testGetTimeGap()
|
||||||
{
|
{
|
||||||
Context::getInstance()->lang = Rhymix\Framework\Lang::getInstance('en');
|
$GLOBALS['lang'] = Rhymix\Framework\Lang::getInstance('en');
|
||||||
Context::getInstance()->lang->loadPlugin('common');
|
$GLOBALS['lang']->loadPlugin('common');
|
||||||
|
|
||||||
// Test getTimeGap() when the internal time zone is different from the default time zone.
|
// Test getTimeGap() when the internal time zone is different from the default time zone.
|
||||||
Rhymix\Framework\Config::set('locale.internal_timezone', 10800);
|
Rhymix\Framework\Config::set('locale.internal_timezone', 10800);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue