当前位置: 首页>>代码示例>>PHP>>正文


PHP CopixI18N::instance方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:BackupTheBerlios,项目名称:phpaie,代码行数:69,代码来源:CopixI18N.class.php

示例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;
     }
 }
开发者ID:BackupTheBerlios,项目名称:phpannu-svn,代码行数:54,代码来源:CopixI18N.class.php


注:本文中的CopixI18N::instance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。