本文整理汇总了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;
}
示例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;
}
示例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;
}