當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CChoiceFormat類代碼示例

本文整理匯總了PHP中CChoiceFormat的典型用法代碼示例。如果您正苦於以下問題:PHP CChoiceFormat類的具體用法?PHP CChoiceFormat怎麽用?PHP CChoiceFormat使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CChoiceFormat類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: t

 /**
  * Translates a message to the specified language.
  * Starting from version 1.0.2, this method supports choice format (see {@link CChoiceFormat}),
  * i.e., the message returned will be chosen from a few candidates according to the given
  * number value. This feature is mainly used to solve plural format issue in case
  * a message has different plural forms in some languages.
  * @param string message category. Please use only word letters. Note, category 'yii' is
  * reserved for Yii framework core code use. See {@link CPhpMessageSource} for
  * more interpretation about message category.
  * @param string the original message
  * @param array parameters to be applied to the message using <code>strtr</code>.
  * Starting from version 1.0.2, the first parameter can be a number without key.
  * And in this case, the method will call {@link CChoiceFormat::format} to choose
  * an appropriate message translation.
  * @param string which message source application component to use.
  * Defaults to null, meaning using 'coreMessages' for messages belonging to
  * the 'yii' category and using 'messages' for the rest messages.
  * @param string the target language. If null (default), the {@link CApplication::getLanguage application language} will be used.
  * This parameter has been available since version 1.0.3.
  * @return string the translated message
  * @see CMessageSource
  */
 public static function t($category, $message, $params = array(), $source = null, $language = null)
 {
     if (self::$_app !== null) {
         if ($source === null) {
             $source = $category === 'yii' || $category === 'zii' ? 'coreMessages' : 'messages';
         }
         if (($source = self::$_app->getComponent($source)) !== null) {
             $message = $source->translate($category, $message, $language);
         }
     }
     if ($params === array()) {
         return $message;
     }
     if (isset($params[0])) {
         $message = CChoiceFormat::format($message, $params[0]);
         unset($params[0]);
     }
     return $params !== array() ? strtr($message, $params) : $message;
 }
開發者ID:kscott,項目名稱:checkin-proto,代碼行數:41,代碼來源:YiiBase.php

示例2: t

 public static function t($category, $message, $params = array(), $source = null, $language = null)
 {
     if (self::$_app !== null) {
         if ($source === null) {
             $source = $category === 'yii' || $category === 'zii' ? 'coreMessages' : 'messages';
         }
         if (($source = self::$_app->getComponent($source)) !== null) {
             $message = $source->translate($category, $message, $language);
         }
     }
     if ($params === array()) {
         return $message;
     }
     if (!is_array($params)) {
         $params = array($params);
     }
     if (isset($params[0])) {
         if (strpos($message, '|') !== false) {
             if (strpos($message, '#') === false) {
                 $chunks = explode('|', $message);
                 $expressions = self::$_app->getLocale($language)->getPluralRules();
                 if ($n = min(count($chunks), count($expressions))) {
                     for ($i = 0; $i < $n; $i++) {
                         $chunks[$i] = $expressions[$i] . '#' . $chunks[$i];
                     }
                     $message = implode('|', $chunks);
                 }
             }
             $message = CChoiceFormat::format($message, $params[0]);
         }
         if (!isset($params['{n}'])) {
             $params['{n}'] = $params[0];
         }
         unset($params[0]);
     }
     return $params !== array() ? strtr($message, $params) : $message;
 }
開發者ID:smokeelow,項目名稱:faicore,代碼行數:37,代碼來源:yiilite.php

示例3: getGeocodingInfo

 /**
  * 
  * Connection to Google Maps' API web service
  * 
  * Modified to include a template for api
  * just in case the url changes in future releases
  * Includes template parsing and CURL calls
  * @author Antonio Ramirez Cobos
  * @since 2010-12-21
  * 
  * @param string $address
  * @param string $format 'csv' or 'xml'
  * @return string
  * @author fabriceb
  * @since 2009-06-17
  * @since 2010-12-22 cUrl and Yii adaptation Antonio Ramirez
  * 
  */
 public function getGeocodingInfo($address, $format = 'csv')
 {
     $apiUrl = CChoiceFormat::format($this->geoCodingInfotemplate, array('{api}' => self::API_URL, '{format}' => $format, '{key}' => $this->getAPIKey(), '{address}' => urlencode($address)));
     $apiURL = self::API_URL . '&output=' . $format . '&key=' . $this->getAPIKey() . '&q=' . urlencode($address);
     if (function_exists('curl_version')) {
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $apiURL);
         curl_setopt($ch, CURLOPT_HEADER, 0);
         curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
         //	curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         $raw_data = curl_exec($ch);
         curl_close($ch);
     } else {
         // no CUrl, try differently
         $raw_data = file_get_contents($apiURL);
     }
     return $raw_data;
 }
開發者ID:romeo14,項目名稱:pow,代碼行數:38,代碼來源:EGMapClient.php


注:本文中的CChoiceFormat類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。