本文整理汇总了PHP中CopixI18N::instance方法的典型用法代码示例。如果您正苦于以下问题:PHP CopixI18N::instance方法的具体用法?PHP CopixI18N::instance怎么用?PHP CopixI18N::instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CopixI18N
的用法示例。
在下文中一共展示了CopixI18N::instance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get
/**
* gets the correct string, for a given language.
* if it can't get the correct language, it will try to gets the string
* from the default language.
* if both fails, it will raise a fatal_error.
*/
function get($key, $args = null, $locale = null)
{
$me =& CopixI18N::instance();
//finds out required lang / coutry
if ($locale === null) {
$plug =& $GLOBALS['COPIX']['COORD']->getPlugin('i18n');
if ($plug === null) {
$lang = $GLOBALS['COPIX']['CONFIG']->default_language;
$country = $GLOBALS['COPIX']['CONFIG']->default_country;
} else {
$lang = $plug->getLang();
$country = $plug->getCountry();
}
} else {
$ext = explode('_', $locale);
if (count($ext) > 1) {
$lang = $ext[0];
$country = $ext[1];
} else {
$lang = $ext[0];
$country = $ext[0];
}
}
//Gets the bundle for the given language.
$trans =& CopixSelectorFactory::create($key);
if (!$trans->isValid) {
trigger_error(CopixI18N::get('copix:copix.error.i18n.keyNotExists', $key), E_USER_ERROR);
}
$messageId = $trans->fileName;
$trans->fileName = substr($trans->fileName, 0, strpos($trans->fileName, '.'));
$bundle =& $me->getBundle($trans, $lang);
//try to get the message from the bundle.
$string = $bundle->get($messageId, $country);
if ($string === null) {
//if the message was not found, we're gonna
//use the default language and country.
if ($lang == $GLOBALS['COPIX']['CONFIG']->default_language && $country == $GLOBALS['COPIX']['CONFIG']->default_country) {
if ($key == 'copix:copix.error.i18n.keyNotExists') {
$msg = 'Can\'t find message key (which should actually be THIS message): ' . $key;
} else {
$msg = CopixI18N::get('copix:copix.error.i18n.keyNotExists', $key);
}
trigger_error($msg, E_USER_ERROR);
}
return $me->get($key, $args, $GLOBALS['COPIX']['CONFIG']->default_language . '_' . $GLOBALS['COPIX']['CONFIG']->default_country);
} else {
//here, we know the message
if ($args !== null) {
$string = call_user_func_array('sprintf', array_merge($string, $args));
/*
// if(is_array($args)){
switch(count($args)){
case 1: $string=sprintf($string,$args[0]); break;
case 2: $string=sprintf($string,$args[0],$args[1]); break;
case 3: $string=sprintf($string,$args[0],$args[1],$args[2]); break;
}
// }else
// $string=sprintf($string,$args);
*/
}
return $string;
}
}
示例2: get
/**
* gets the correct string, for a given language.
* if it can't get the correct language, it will try to gets the string
* from the default language.
* if both fails, it will raise a fatal_error.
*/
function get($key, $args = null, $locale = null)
{
$me =& CopixI18N::instance();
//finds out required lang / coutry
if ($locale === null) {
$lang = $GLOBALS['COPIX']['CONFIG']->default_language;
// rempli par le plugin egalement
$country = $GLOBALS['COPIX']['CONFIG']->default_country;
} else {
$ext = explode('_', $locale);
if (count($ext) > 1) {
$lang = $ext[0];
$country = $ext[1];
} else {
$lang = $ext[0];
$country = $ext[0];
}
}
//Gets the bundle for the given language.
$keySelector = substr($key, 0, strpos($key, '.'));
$trans =& CopixSelectorFactory::create($keySelector);
if (!$trans->isValid) {
trigger_error(CopixI18N::get('copix:copix.error.i18n.keyNotExists', $key), E_USER_ERROR);
}
$key = $me->_extractMessageKey($key);
$bundle =& $me->getBundle($trans, $lang);
//try to get the message from the bundle.
$string = $bundle->get($key, $country);
if ($string === null) {
//if the message was not found, we're gonna
//use the default language and country.
if ($lang == $GLOBALS['COPIX']['CONFIG']->default_language && $country == $GLOBALS['COPIX']['CONFIG']->default_country) {
if ($key == 'copix:copix.error.i18n.keyNotExists') {
$msg = 'Can\'t find message key (which should actually be THIS message): ' . $key;
} else {
$msg = CopixI18N::get('copix:copix.error.i18n.keyNotExists', $key);
}
trigger_error($msg, E_USER_ERROR);
}
return $me->get($key, $args, $GLOBALS['COPIX']['CONFIG']->default_language . '_' . $GLOBALS['COPIX']['CONFIG']->default_country);
} else {
//here, we know the message
if ($args !== null) {
$string = call_user_func_array('sprintf', array_merge($string, $args));
}
return $string;
}
}