/** * 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; }
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; }
/** * * 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; }