pixmicat

Subversion Repositories:
Compare Path: Rev
With Path: Rev
/PIO/ @ 863  →  /PIO/ @ 864

Property changes:

Name: svn:keywords
+ Id Date Author

/PIO/lib/lib_compatible.php
@@ -3,7 +3,7 @@
* Pixmicat! compatible components
*
* @package PMCLibrary
* @version $Id: lib_language.php 833 2012-12-13 15:50:32Z scribe $
* @version $Id$
*/
 
/**
/PIO/lib/lib_language.php
@@ -9,6 +9,8 @@
class LanguageLoader {
private $locale;
private $language;
private $languageFallback;
private $hasFallback;
 
private function __construct($locale, array $language) {
$this->locale = $locale;
@@ -19,24 +21,43 @@
* 取得語言物件之單例。
*
* @return LanguageLoader 語言物件
* @throws InvalidArgumentException 如果找不到設定語言
*/
public static function getInstance() {
static $inst = null;
if ($inst == null) {
$locale = PIXMICAT_LANGUAGE;
$langFile = ROOTPATH."lib/lang/$locale.php";
if (file_exists($langFile)){
$langFile = ROOTPATH."lib/lang/{$locale}.php";
if (file_exists($langFile)) {
require $langFile;
} else {
$locale = 'en_US';
require ROOTPATH.'lib/lang/en_US.php';
throw new InvalidArgumentException(
sprintf('Assigned locale: %s not found.', $locale)
);
}
$inst = new LanguageLoader($locale, $language);
$inst->setFallback('en_US');
}
return $inst;
}
 
/**
* 設定備用語系。
*
* @param string $localeFallback 備用語系
*/
public function setFallback($localeFallback = 'en_US') {
if ($localeFallback != $this->getLocale()) {
require ROOTPATH."lib/lang/{$localeFallback}.php";
$this->hasFallback = true;
$this->languageFallback = $language;
} else {
// 備用無效
$this->hasFallback = false;
}
}
 
/**
* 取得語系設定。
*
* @see PIXMICAT_LANGUAGE
@@ -62,10 +83,11 @@
* @return string 對應文字
*/
private function getTranslationBody($index) {
$str = $index;
if (array_key_exists($index, $this->language)) {
$str = $this->language[$index];
} else {
$str = $index;
} else if ($this->hasFallback && array_key_exists($index, $this->languageFallback)) {
$str = $this->languageFallback[$index];
}
return $str;
}

Property changes:

Name: svn:keywords
+ Id Date Author

/PIO/lib/lib_noplogger.php
@@ -5,7 +5,7 @@
* Because there is no traceable information left to provide for debugging.
*
* @package PMCLibrary
* @version $Id: lib_simplelogger.php 833 2012-12-13 15:50:32Z scribe $
* @version $Id$
*/
 
class NopLogger implements ILogger {
/PIO/lib/lib_pms.php
@@ -212,6 +212,30 @@
* @param array $lang 翻譯資源字串陣列
*/
protected function attachLanguage(array $lang) {
$langKeys = array_keys($lang);
// 為字串資源鍵值加上模組名前綴
foreach ($langKeys as $k) {
$lang[$this->clazz.'_'.$k] = $lang[$k];
unset($lang[$k]);
}
 
PMCLibrary::getLanguageInstance()->attachLanguage($lang);
}
 
/**
* 取出翻譯資源檔對應字串。
*
* @param args 翻譯資源檔索引、其餘變數
* @see LanguageLoader->getTranslation
*/
protected function _T() {
$args = func_get_args();
// 為字串資源鍵值加上模組名前綴
if (isset($args[0]) && !empty($args[0])) {
$args[0] = $this->clazz.'_'.$args[0];
}
return call_user_func_array(
array(PMCLibrary::getLanguageInstance(), 'getTranslation'),
$args);
}
}