diff --git a/framework/YiiBase.php b/framework/YiiBase.php
index d01648c..be59c16 100644
--- a/framework/YiiBase.php
+++ b/framework/YiiBase.php
@@ -507,9 +507,6 @@ class YiiBase
* 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 $category 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 $message the original message
* @param array $params parameters to be applied to the message using strtr
.
* The first parameter can be a number without key.
@@ -517,62 +514,12 @@ class YiiBase
* an appropriate message translation.
* You can pass parameter for {@link CChoiceFormat::format}
* or plural forms format without wrapping it with array.
- * @param string $source 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 $language the target language. If null (default), the {@link CApplication::getLanguage application language} will be used.
* @return string the translated message
* @see CMessageSource
*/
- public static function t($category, $message, $params = array(), $source = null, $language = null)
+ public static function t($message, $params = array(), $language = null)
{
- // todo;
- return $params !== array() ? strtr($message, $params) : $message;
- if (self::$application !== null)
- {
- if ($source === null)
- {
- $source = $category === 'yii' ? 'coreMessages' : 'messages';
- }
- if (($source = self::$application->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])) // number choice
- {
- if (strpos($message, '|') !== false)
- {
- if (strpos($message, '#') === false)
- {
- $chunks = explode('|', $message);
- $expressions = self::$application->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;
+ Yii::$application->getI18N()->translate($message, $params, $language);
}
}
diff --git a/framework/base/Application.php b/framework/base/Application.php
index cd77f1f..e4c1333 100644
--- a/framework/base/Application.php
+++ b/framework/base/Application.php
@@ -30,10 +30,6 @@ use yii\util\FileHelper;
* persistence method. This application component is dynamically loaded when needed.
*
+ * return array( + * 'original message 1' => 'translated message 1', + * 'original message 2' => 'translated message 2', + * ); + *+ *
+ * array( + * 'ExtensionName' => 'ext.ExtensionName.messages', + * ) + *+ * Where the key is the name of the extension and the value is the alias to the path + * of the "messages" subdirectory of the extension. + * When using Yii::t() to translate an extension message, the category name should be + * set as 'ExtensionName.categoryName'. + * Defaults to an empty array, meaning no extensions registered. + * @since 1.1.13 + */ + public $extensionPaths=array(); + + private $_files=array(); + + /** + * Initializes the application component. + * This method overrides the parent implementation by preprocessing + * the user request data. + */ + public function init() + { + parent::init(); + if($this->basePath===null) + $this->basePath=Yii::getPathOfAlias('application.messages'); + } + + /** + * Determines the message file name based on the given category and language. + * If the category name contains a dot, it will be split into the module class name and the category name. + * In this case, the message file will be assumed to be located within the 'messages' subdirectory of + * the directory containing the module class file. + * Otherwise, the message file is assumed to be under the {@link basePath}. + * @param string $category category name + * @param string $language language ID + * @return string the message file path + */ + protected function getMessageFile($category,$language) + { + if(!isset($this->_files[$category][$language])) + { + if(($pos=strpos($category,'.'))!==false) + { + $extensionClass=substr($category,0,$pos); + $extensionCategory=substr($category,$pos+1); + // First check if there's an extension registered for this class. + if(isset($this->extensionPaths[$extensionClass])) + $this->_files[$category][$language]=Yii::getPathOfAlias($this->extensionPaths[$extensionClass]).DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.$extensionCategory.'.php'; + else + { + // No extension registered, need to find it. + $class=new ReflectionClass($extensionClass); + $this->_files[$category][$language]=dirname($class->getFileName()).DIRECTORY_SEPARATOR.'messages'.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.$extensionCategory.'.php'; + } + } + else + $this->_files[$category][$language]=$this->basePath.DIRECTORY_SEPARATOR.$language.DIRECTORY_SEPARATOR.$category.'.php'; + } + return $this->_files[$category][$language]; + } + + /** + * Loads the message translation for the specified language and category. + * @param string $category the message category + * @param string $language the target language + * @return array the loaded messages + */ + protected function loadMessages($category,$language) + { + $messageFile=$this->getMessageFile($category,$language); + + if($this->cachingDuration>0 && $this->cacheID!==false && ($cache=Yii::app()->getComponent($this->cacheID))!==null) + { + $key=self::CACHE_KEY_PREFIX . $messageFile; + if(($data=$cache->get($key))!==false) + return unserialize($data); + } + + if(is_file($messageFile)) + { + $messages=include($messageFile); + if(!is_array($messages)) + $messages=array(); + if(isset($cache)) + { + $dependency=new CFileCacheDependency($messageFile); + $cache->set($key,serialize($messages),$this->cachingDuration,$dependency); + } + return $messages; + } + else + return array(); + } +} \ No newline at end of file diff --git a/framework/logging/EmailTarget.php b/framework/logging/EmailTarget.php index e02e4da..205cd06 100644 --- a/framework/logging/EmailTarget.php +++ b/framework/logging/EmailTarget.php @@ -50,7 +50,7 @@ class EmailTarget extends Target $body .= $this->formatMessage($message); } $body = wordwrap($body, 70); - $subject = $this->subject === null ? \Yii::t('yii', 'Application Log') : $this->subject; + $subject = $this->subject === null ? \Yii::t('yii:Application Log') : $this->subject; foreach ($this->emails as $email) { $this->sendEmail($subject, $body, $email, $this->sentFrom, $this->headers); } diff --git a/framework/logging/ProfileTarget.php b/framework/logging/ProfileTarget.php index 716e6b7..30a207c 100644 --- a/framework/logging/ProfileTarget.php +++ b/framework/logging/ProfileTarget.php @@ -61,7 +61,7 @@ class CProfileLogRoute extends CWebLogRoute if ($value === 'summary' || $value === 'callstack') $this->_report = $value; else - throw new CException(Yii::t('yii', 'CProfileLogRoute.report "{report}" is invalid. Valid values include "summary" and "callstack".', + throw new CException(Yii::t('yii:CProfileLogRoute.report "{report}" is invalid. Valid values include "summary" and "callstack".', array('{report}' => $value))); } @@ -108,7 +108,7 @@ class CProfileLogRoute extends CWebLogRoute $results[$last[4]] = array($token, $delta, count($stack)); } else { - throw new CException(Yii::t('yii', 'CProfileLogRoute found a mismatching code block "{token}". Make sure the calls to Yii::beginProfile() and Yii::endProfile() be properly nested.', + throw new CException(Yii::t('yii:CProfileLogRoute found a mismatching code block "{token}". Make sure the calls to Yii::beginProfile() and Yii::endProfile() be properly nested.', array('{token}' => $token))); } } @@ -151,7 +151,7 @@ class CProfileLogRoute extends CWebLogRoute else $results[$token] = array($token, 1, $delta, $delta, $delta); } else - throw new CException(Yii::t('yii', 'CProfileLogRoute found a mismatching code block "{token}". Make sure the calls to Yii::beginProfile() and Yii::endProfile() be properly nested.', + throw new CException(Yii::t('yii:CProfileLogRoute found a mismatching code block "{token}". Make sure the calls to Yii::beginProfile() and Yii::endProfile() be properly nested.', array('{token}' => $token))); } } diff --git a/framework/validators/BooleanValidator.php b/framework/validators/BooleanValidator.php index 90e7939..a002ba5 100644 --- a/framework/validators/BooleanValidator.php +++ b/framework/validators/BooleanValidator.php @@ -54,7 +54,7 @@ class BooleanValidator extends Validator } if (!$this->strict && $value != $this->trueValue && $value != $this->falseValue || $this->strict && $value !== $this->trueValue && $value !== $this->falseValue) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} must be either {true} or {false}.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} must be either {true} or {false}.'); $this->addError($object, $attribute, $message, array( '{true}' => $this->trueValue, '{false}' => $this->falseValue, @@ -70,7 +70,7 @@ class BooleanValidator extends Validator */ public function clientValidateAttribute($object, $attribute) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} must be either {true} or {false}.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} must be either {true} or {false}.'); $message = strtr($message, array( '{attribute}' => $object->getAttributeLabel($attribute), '{value}' => $object->$attribute, diff --git a/framework/validators/CaptchaValidator.php b/framework/validators/CaptchaValidator.php index 3da8ed6..e936f63 100644 --- a/framework/validators/CaptchaValidator.php +++ b/framework/validators/CaptchaValidator.php @@ -49,7 +49,7 @@ class CaptchaValidator extends Validator } $captcha = $this->getCaptchaAction(); if (!$captcha->validate($value, $this->caseSensitive)) { - $message = $this->message !== null ? $this->message : \Yii::t('yii', 'The verification code is incorrect.'); + $message = $this->message !== null ? $this->message : \Yii::t('yii:The verification code is incorrect.'); $this->addError($object, $attribute, $message); } } @@ -85,7 +85,7 @@ class CaptchaValidator extends Validator public function clientValidateAttribute($object, $attribute) { $captcha = $this->getCaptchaAction(); - $message = $this->message !== null ? $this->message : \Yii::t('yii', 'The verification code is incorrect.'); + $message = $this->message !== null ? $this->message : \Yii::t('yii:The verification code is incorrect.'); $message = strtr($message, array( '{attribute}' => $object->getAttributeLabel($attribute), '{value}' => $object->$attribute, diff --git a/framework/validators/CompareValidator.php b/framework/validators/CompareValidator.php index 9345b73..141cb16 100644 --- a/framework/validators/CompareValidator.php +++ b/framework/validators/CompareValidator.php @@ -96,37 +96,37 @@ class CompareValidator extends Validator case '=': case '==': if (($this->strict && $value !== $compareValue) || (!$this->strict && $value != $compareValue)) { - $message = ($this->message !== null) ? $this->message : Yii::t('yii', '{attribute} must be repeated exactly.'); + $message = ($this->message !== null) ? $this->message : Yii::t('yii:{attribute} must be repeated exactly.'); $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareLabel)); } break; case '!=': if (($this->strict && $value === $compareValue) || (!$this->strict && $value == $compareValue)) { - $message = ($this->message !== null) ? $this->message : Yii::t('yii', '{attribute} must not be equal to "{compareValue}".'); + $message = ($this->message !== null) ? $this->message : Yii::t('yii:{attribute} must not be equal to "{compareValue}".'); $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareLabel, '{compareValue}' => $compareValue)); } break; case '>': if ($value <= $compareValue) { - $message = ($this->message !== null) ? $this->message : Yii::t('yii', '{attribute} must be greater than "{compareValue}".'); + $message = ($this->message !== null) ? $this->message : Yii::t('yii:{attribute} must be greater than "{compareValue}".'); $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareLabel, '{compareValue}' => $compareValue)); } break; case '>=': if ($value < $compareValue) { - $message = ($this->message !== null) ? $this->message : Yii::t('yii', '{attribute} must be greater than or equal to "{compareValue}".'); + $message = ($this->message !== null) ? $this->message : Yii::t('yii:{attribute} must be greater than or equal to "{compareValue}".'); $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareLabel, '{compareValue}' => $compareValue)); } break; case '<': if ($value >= $compareValue) { - $message = ($this->message !== null) ? $this->message : Yii::t('yii', '{attribute} must be less than "{compareValue}".'); + $message = ($this->message !== null) ? $this->message : Yii::t('yii:{attribute} must be less than "{compareValue}".'); $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareLabel, '{compareValue}' => $compareValue)); } break; case '<=': if ($value > $compareValue) { - $message = ($this->message !== null) ? $this->message : Yii::t('yii', '{attribute} must be less than or equal to "{compareValue}".'); + $message = ($this->message !== null) ? $this->message : Yii::t('yii:{attribute} must be less than or equal to "{compareValue}".'); $this->addError($object, $attribute, $message, array('{compareAttribute}' => $compareLabel, '{compareValue}' => $compareValue)); } break; @@ -158,37 +158,37 @@ class CompareValidator extends Validator case '=': case '==': if ($message === null) { - $message = Yii::t('yii', '{attribute} must be repeated exactly.'); + $message = Yii::t('yii:{attribute} must be repeated exactly.'); } $condition = 'value!=' . $compareValue; break; case '!=': if ($message === null) { - $message = Yii::t('yii', '{attribute} must not be equal to "{compareValue}".'); + $message = Yii::t('yii:{attribute} must not be equal to "{compareValue}".'); } $condition = 'value==' . $compareValue; break; case '>': if ($message === null) { - $message = Yii::t('yii', '{attribute} must be greater than "{compareValue}".'); + $message = Yii::t('yii:{attribute} must be greater than "{compareValue}".'); } $condition = 'value<=' . $compareValue; break; case '>=': if ($message === null) { - $message = Yii::t('yii', '{attribute} must be greater than or equal to "{compareValue}".'); + $message = Yii::t('yii:{attribute} must be greater than or equal to "{compareValue}".'); } $condition = 'value<' . $compareValue; break; case '<': if ($message === null) { - $message = Yii::t('yii', '{attribute} must be less than "{compareValue}".'); + $message = Yii::t('yii:{attribute} must be less than "{compareValue}".'); } $condition = 'value>=' . $compareValue; break; case '<=': if ($message === null) { - $message = Yii::t('yii', '{attribute} must be less than or equal to "{compareValue}".'); + $message = Yii::t('yii:{attribute} must be less than or equal to "{compareValue}".'); } $condition = 'value>' . $compareValue; break; diff --git a/framework/validators/DateValidator.php b/framework/validators/DateValidator.php index f4fa866..af97a71 100644 --- a/framework/validators/DateValidator.php +++ b/framework/validators/DateValidator.php @@ -66,7 +66,7 @@ class DateValidator extends Validator } if (!$valid) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', 'The format of {attribute} is invalid.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:The format of {attribute} is invalid.'); $this->addError($object, $attribute, $message); } } diff --git a/framework/validators/EmailValidator.php b/framework/validators/EmailValidator.php index 8fd8120..b78b2da 100644 --- a/framework/validators/EmailValidator.php +++ b/framework/validators/EmailValidator.php @@ -63,7 +63,7 @@ class EmailValidator extends Validator return; } if (!$this->validateValue($value)) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} is not a valid email address.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} is not a valid email address.'); $this->addError($object, $attribute, $message); } } @@ -100,7 +100,7 @@ class EmailValidator extends Validator */ public function clientValidateAttribute($object, $attribute) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} is not a valid email address.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} is not a valid email address.'); $message = strtr($message, array( '{attribute}' => $object->getAttributeLabel($attribute), '{value}' => $object->$attribute, diff --git a/framework/validators/ExistValidator.php b/framework/validators/ExistValidator.php index be710bd..9d253c9 100644 --- a/framework/validators/ExistValidator.php +++ b/framework/validators/ExistValidator.php @@ -68,7 +68,7 @@ class ExistValidator extends Validator $query = $className::find(); $query->where(array($column->name => $value)); if (!$query->exists()) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} "{value}" is invalid.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} "{value}" is invalid.'); $this->addError($object, $attribute, $message); } } diff --git a/framework/validators/FileValidator.php b/framework/validators/FileValidator.php index 106b9a6..c558b76 100644 --- a/framework/validators/FileValidator.php +++ b/framework/validators/FileValidator.php @@ -115,7 +115,7 @@ class CFileValidator extends Validator return $this->emptyAttribute($object, $attribute); if (count($files) > $this->maxFiles) { - $message = $this->tooMany !== null ? $this->tooMany : \Yii::t('yii', '{attribute} cannot accept more than {limit} files.'); + $message = $this->tooMany !== null ? $this->tooMany : \Yii::t('yii:{attribute} cannot accept more than {limit} files.'); $this->addError($object, $attribute, $message, array('{attribute}' => $attribute, '{limit}' => $this->maxFiles)); } else foreach ($files as $file) @@ -145,20 +145,20 @@ class CFileValidator extends Validator return $this->emptyAttribute($object, $attribute); elseif ($error == UPLOAD_ERR_INI_SIZE || $error == UPLOAD_ERR_FORM_SIZE || $this->maxSize !== null && $file->getSize() > $this->maxSize) { - $message = $this->tooLarge !== null ? $this->tooLarge : \Yii::t('yii', 'The file "{file}" is too large. Its size cannot exceed {limit} bytes.'); + $message = $this->tooLarge !== null ? $this->tooLarge : \Yii::t('yii:The file "{file}" is too large. Its size cannot exceed {limit} bytes.'); $this->addError($object, $attribute, $message, array('{file}' => $file->getName(), '{limit}' => $this->getSizeLimit())); } elseif ($error == UPLOAD_ERR_PARTIAL) - throw new CException(\Yii::t('yii', 'The file "{file}" was only partially uploaded.', array('{file}' => $file->getName()))); + throw new CException(\Yii::t('yii:The file "{file}" was only partially uploaded.', array('{file}' => $file->getName()))); elseif ($error == UPLOAD_ERR_NO_TMP_DIR) - throw new CException(\Yii::t('yii', 'Missing the temporary folder to store the uploaded file "{file}".', array('{file}' => $file->getName()))); + throw new CException(\Yii::t('yii:Missing the temporary folder to store the uploaded file "{file}".', array('{file}' => $file->getName()))); elseif ($error == UPLOAD_ERR_CANT_WRITE) - throw new CException(\Yii::t('yii', 'Failed to write the uploaded file "{file}" to disk.', array('{file}' => $file->getName()))); + throw new CException(\Yii::t('yii:Failed to write the uploaded file "{file}" to disk.', array('{file}' => $file->getName()))); elseif (defined('UPLOAD_ERR_EXTENSION') && $error == UPLOAD_ERR_EXTENSION) // available for PHP 5.2.0 or above - throw new CException(\Yii::t('yii', 'File upload was stopped by extension.')); + throw new CException(\Yii::t('yii:File upload was stopped by extension.')); if ($this->minSize !== null && $file->getSize() < $this->minSize) { - $message = $this->tooSmall !== null ? $this->tooSmall : \Yii::t('yii', 'The file "{file}" is too small. Its size cannot be smaller than {limit} bytes.'); + $message = $this->tooSmall !== null ? $this->tooSmall : \Yii::t('yii:The file "{file}" is too small. Its size cannot be smaller than {limit} bytes.'); $this->addError($object, $attribute, $message, array('{file}' => $file->getName(), '{limit}' => $this->minSize)); } @@ -170,7 +170,7 @@ class CFileValidator extends Validator $types = $this->types; if (!in_array(strtolower($file->getExtensionName()), $types)) { - $message = $this->wrongType !== null ? $this->wrongType : \Yii::t('yii', 'The file "{file}" cannot be uploaded. Only files with these extensions are allowed: {extensions}.'); + $message = $this->wrongType !== null ? $this->wrongType : \Yii::t('yii:The file "{file}" cannot be uploaded. Only files with these extensions are allowed: {extensions}.'); $this->addError($object, $attribute, $message, array('{file}' => $file->getName(), '{extensions}' => implode(', ', $types))); } } @@ -185,7 +185,7 @@ class CFileValidator extends Validator { if (!$this->allowEmpty) { - $message = $this->message !== null ? $this->message : \Yii::t('yii', '{attribute} cannot be blank.'); + $message = $this->message !== null ? $this->message : \Yii::t('yii:{attribute} cannot be blank.'); $this->addError($object, $attribute, $message); } } diff --git a/framework/validators/NumberValidator.php b/framework/validators/NumberValidator.php index 4596fc1..d459fb8 100644 --- a/framework/validators/NumberValidator.php +++ b/framework/validators/NumberValidator.php @@ -73,21 +73,21 @@ class NumberValidator extends Validator } if ($this->integerOnly) { if (!preg_match($this->integerPattern, "$value")) { - $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be an integer.'); + $message = $this->message !== null ? $this->message : Yii::t('yii:{attribute} must be an integer.'); $this->addError($object, $attribute, $message); } } else { if (!preg_match($this->numberPattern, "$value")) { - $message = $this->message !== null ? $this->message : Yii::t('yii', '{attribute} must be a number.'); + $message = $this->message !== null ? $this->message : Yii::t('yii:{attribute} must be a number.'); $this->addError($object, $attribute, $message); } } if ($this->min !== null && $value < $this->min) { - $message = $this->tooSmall !== null ? $this->tooSmall : Yii::t('yii', '{attribute} is too small (minimum is {min}).'); + $message = $this->tooSmall !== null ? $this->tooSmall : Yii::t('yii:{attribute} is too small (minimum is {min}).'); $this->addError($object, $attribute, $message, array('{min}' => $this->min)); } if ($this->max !== null && $value > $this->max) { - $message = $this->tooBig !== null ? $this->tooBig : Yii::t('yii', '{attribute} is too big (maximum is {max}).'); + $message = $this->tooBig !== null ? $this->tooBig : Yii::t('yii:{attribute} is too big (maximum is {max}).'); $this->addError($object, $attribute, $message, array('{max}' => $this->max)); } } @@ -103,8 +103,8 @@ class NumberValidator extends Validator $label = $object->getAttributeLabel($attribute); if (($message = $this->message) === null) { - $message = $this->integerOnly ? Yii::t('yii', '{attribute} must be an integer.') - : Yii::t('yii', '{attribute} must be a number.'); + $message = $this->integerOnly ? Yii::t('yii:{attribute} must be an integer.') + : Yii::t('yii:{attribute} must be a number.'); } $message = strtr($message, array( '{attribute}' => $label, @@ -118,7 +118,7 @@ if(!value.match($pattern)) { "; if ($this->min !== null) { if (($tooSmall = $this->tooSmall) === null) { - $tooSmall = Yii::t('yii', '{attribute} is too small (minimum is {min}).'); + $tooSmall = Yii::t('yii:{attribute} is too small (minimum is {min}).'); } $tooSmall = strtr($tooSmall, array( '{attribute}' => $label, @@ -133,7 +133,7 @@ if(value<{$this->min}) { } if ($this->max !== null) { if (($tooBig = $this->tooBig) === null) { - $tooBig = Yii::t('yii', '{attribute} is too big (maximum is {max}).'); + $tooBig = Yii::t('yii:{attribute} is too big (maximum is {max}).'); } $tooBig = strtr($tooBig, array( '{attribute}' => $label, diff --git a/framework/validators/RangeValidator.php b/framework/validators/RangeValidator.php index b2ff773..6abf81f 100644 --- a/framework/validators/RangeValidator.php +++ b/framework/validators/RangeValidator.php @@ -58,10 +58,10 @@ class RangeValidator extends Validator throw new InvalidConfigException('The "range" property must be specified as an array.'); } if (!$this->not && !in_array($value, $this->range, $this->strict)) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} should be in the list.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} should be in the list.'); $this->addError($object, $attribute, $message); } elseif ($this->not && in_array($value, $this->range, $this->strict)) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} should NOT be in the list.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} should NOT be in the list.'); $this->addError($object, $attribute, $message); } } @@ -80,7 +80,7 @@ class RangeValidator extends Validator } if (($message = $this->message) === null) { - $message = $this->not ? \Yii::t('yii', '{attribute} should NOT be in the list.') : \Yii::t('yii', '{attribute} should be in the list.'); + $message = $this->not ? \Yii::t('yii:{attribute} should NOT be in the list.') : \Yii::t('yii:{attribute} should be in the list.'); } $message = strtr($message, array( '{attribute}' => $object->getAttributeLabel($attribute), diff --git a/framework/validators/RegularExpressionValidator.php b/framework/validators/RegularExpressionValidator.php index fbdb062..1e034f7 100644 --- a/framework/validators/RegularExpressionValidator.php +++ b/framework/validators/RegularExpressionValidator.php @@ -51,7 +51,7 @@ class RegularExpressionValidator extends Validator throw new \yii\base\Exception('The "pattern" property must be specified with a valid regular expression.'); } if ((!$this->not && !preg_match($this->pattern, $value)) || ($this->not && preg_match($this->pattern, $value))) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} is invalid.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} is invalid.'); $this->addError($object, $attribute, $message); } } @@ -69,7 +69,7 @@ class RegularExpressionValidator extends Validator throw new \yii\base\Exception('The "pattern" property must be specified with a valid regular expression.'); } - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} is invalid.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} is invalid.'); $message = strtr($message, array( '{attribute}' => $object->getAttributeLabel($attribute), '{value}' => $object->$attribute, diff --git a/framework/validators/RequiredValidator.php b/framework/validators/RequiredValidator.php index f0f4bfd..af03221 100644 --- a/framework/validators/RequiredValidator.php +++ b/framework/validators/RequiredValidator.php @@ -47,12 +47,12 @@ class RequiredValidator extends Validator $value = $object->$attribute; if ($this->requiredValue === null) { if ($this->strict && $value === null || !$this->strict && $this->isEmpty($value, true)) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} cannot be blank.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} cannot be blank.'); $this->addError($object, $attribute, $message); } } else { if (!$this->strict && $value != $this->requiredValue || $this->strict && $value !== $this->requiredValue) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} must be "{requiredValue}".'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} must be "{requiredValue}".'); $this->addError($object, $attribute, $message, array( '{requiredValue}' => $this->requiredValue, )); @@ -71,7 +71,7 @@ class RequiredValidator extends Validator $message = $this->message; if ($this->requiredValue !== null) { if ($message === null) { - $message = \Yii::t('yii', '{attribute} must be "{requiredValue}".'); + $message = \Yii::t('yii:{attribute} must be "{requiredValue}".'); } $message = strtr($message, array( '{attribute}' => $object->getAttributeLabel($attribute), @@ -85,7 +85,7 @@ if (value != " . json_encode($this->requiredValue) . ") { "; } else { if ($message === null) { - $message = \Yii::t('yii', '{attribute} cannot be blank.'); + $message = \Yii::t('yii:{attribute} cannot be blank.'); } $message = strtr($message, array( '{attribute}' => $object->getAttributeLabel($attribute), diff --git a/framework/validators/StringValidator.php b/framework/validators/StringValidator.php index fe69a4d..4db29d3 100644 --- a/framework/validators/StringValidator.php +++ b/framework/validators/StringValidator.php @@ -76,7 +76,7 @@ class StringValidator extends Validator } if (!is_string($value)) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} must be a string.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} must be a string.'); $this->addError($object, $attribute, $message); return; } @@ -88,15 +88,15 @@ class StringValidator extends Validator } if ($this->min !== null && $length < $this->min) { - $message = ($this->tooShort !== null) ? $this->tooShort : \Yii::t('yii', '{attribute} is too short (minimum is {min} characters).'); + $message = ($this->tooShort !== null) ? $this->tooShort : \Yii::t('yii:{attribute} is too short (minimum is {min} characters).'); $this->addError($object, $attribute, $message, array('{min}' => $this->min)); } if ($this->max !== null && $length > $this->max) { - $message = ($this->tooLong !== null) ? $this->tooLong : \Yii::t('yii', '{attribute} is too long (maximum is {max} characters).'); + $message = ($this->tooLong !== null) ? $this->tooLong : \Yii::t('yii:{attribute} is too long (maximum is {max} characters).'); $this->addError($object, $attribute, $message, array('{max}' => $this->max)); } if ($this->is !== null && $length !== $this->is) { - $message = ($this->notEqual !== null) ? $this->notEqual : \Yii::t('yii', '{attribute} is of the wrong length (should be {length} characters).'); + $message = ($this->notEqual !== null) ? $this->notEqual : \Yii::t('yii:{attribute} is of the wrong length (should be {length} characters).'); $this->addError($object, $attribute, $message, array('{length}' => $this->is)); } } @@ -113,7 +113,7 @@ class StringValidator extends Validator $value = $object->$attribute; if (($notEqual = $this->notEqual) === null) { - $notEqual = \Yii::t('yii', '{attribute} is of the wrong length (should be {length} characters).'); + $notEqual = \Yii::t('yii:{attribute} is of the wrong length (should be {length} characters).'); } $notEqual = strtr($notEqual, array( '{attribute}' => $label, @@ -122,7 +122,7 @@ class StringValidator extends Validator )); if (($tooShort = $this->tooShort) === null) { - $tooShort = \Yii::t('yii', '{attribute} is too short (minimum is {min} characters).'); + $tooShort = \Yii::t('yii:{attribute} is too short (minimum is {min} characters).'); } $tooShort = strtr($tooShort, array( '{attribute}' => $label, @@ -131,7 +131,7 @@ class StringValidator extends Validator )); if (($tooLong = $this->tooLong) === null) { - $tooLong = \Yii::t('yii', '{attribute} is too long (maximum is {max} characters).'); + $tooLong = \Yii::t('yii:{attribute} is too long (maximum is {max} characters).'); } $tooLong = strtr($tooLong, array( '{attribute}' => $label, diff --git a/framework/validators/UniqueValidator.php b/framework/validators/UniqueValidator.php index 5d5e603..758d44f 100644 --- a/framework/validators/UniqueValidator.php +++ b/framework/validators/UniqueValidator.php @@ -86,7 +86,7 @@ class UniqueValidator extends Validator } if ($exists) { - $message = $this->message !== null ? $this->message : \Yii::t('yii', '{attribute} "{value}" has already been taken.'); + $message = $this->message !== null ? $this->message : \Yii::t('yii:{attribute} "{value}" has already been taken.'); $this->addError($object, $attribute, $message); } } diff --git a/framework/validators/UrlValidator.php b/framework/validators/UrlValidator.php index c6242a2..768e8d4 100644 --- a/framework/validators/UrlValidator.php +++ b/framework/validators/UrlValidator.php @@ -55,7 +55,7 @@ class UrlValidator extends Validator if (($value = $this->validateValue($value)) !== false) { $object->$attribute = $value; } else { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} is not a valid URL.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} is not a valid URL.'); $this->addError($object, $attribute, $message); } } @@ -97,7 +97,7 @@ class UrlValidator extends Validator */ public function clientValidateAttribute($object, $attribute) { - $message = ($this->message !== null) ? $this->message : \Yii::t('yii', '{attribute} is not a valid URL.'); + $message = ($this->message !== null) ? $this->message : \Yii::t('yii:{attribute} is not a valid URL.'); $message = strtr($message, array( '{attribute}' => $object->getAttributeLabel($attribute), '{value}' => $object->$attribute, diff --git a/framework/web/AssetManager.php b/framework/web/AssetManager.php index 2028a1c..bf27e6a 100644 --- a/framework/web/AssetManager.php +++ b/framework/web/AssetManager.php @@ -113,7 +113,7 @@ class CAssetManager extends CApplicationComponent if(($basePath=realpath($value))!==false && is_dir($basePath) && is_writable($basePath)) $this->_basePath=$basePath; else - throw new CException(Yii::t('yii','CAssetManager.basePath "{path}" is invalid. Please make sure the directory exists and is writable by the Web server process.', + throw new CException(Yii::t('yii:CAssetManager.basePath "{path}" is invalid. Please make sure the directory exists and is writable by the Web server process.', array('{path}'=>$value))); } @@ -236,7 +236,7 @@ class CAssetManager extends CApplicationComponent return $this->_published[$path]=$this->getBaseUrl().'/'.$dir; } } - throw new CException(Yii::t('yii','The asset "{asset}" to be published does not exist.', + throw new CException(Yii::t('yii:The asset "{asset}" to be published does not exist.', array('{asset}'=>$path))); } diff --git a/framework/web/Controller.php b/framework/web/Controller.php index 92722b5..e4c36c9 100644 --- a/framework/web/Controller.php +++ b/framework/web/Controller.php @@ -45,7 +45,7 @@ class Controller extends \yii\base\Controller */ public function invalidActionParams($action, $exception) { - throw new HttpException(400, \Yii::t('yii', 'Your request is invalid.')); + throw new HttpException(400, \Yii::t('yii:Your request is invalid.')); } /** diff --git a/framework/web/Request.php b/framework/web/Request.php index 09e4864..9566974 100644 --- a/framework/web/Request.php +++ b/framework/web/Request.php @@ -823,7 +823,7 @@ class Request extends \yii\base\Request $valid = false; } if (!$valid) { - throw new CHttpException(400, Yii::t('yii', 'The CSRF token could not be verified.')); + throw new CHttpException(400, Yii::t('yii:The CSRF token could not be verified.')); } } } diff --git a/framework/web/Session.php b/framework/web/Session.php index 4544fc0..2b23e62 100644 --- a/framework/web/Session.php +++ b/framework/web/Session.php @@ -115,7 +115,7 @@ class CHttpSession extends CApplicationComponent implements IteratorAggregate,Ar @session_start(); if(YII_DEBUG && session_id()=='') { - $message=Yii::t('yii','Failed to start session.'); + $message=Yii::t('yii:Failed to start session.'); if(function_exists('error_get_last')) { $error=error_get_last(); @@ -215,7 +215,7 @@ class CHttpSession extends CApplicationComponent implements IteratorAggregate,Ar if(is_dir($value)) session_save_path($value); else - throw new CException(Yii::t('yii','CHttpSession.savePath "{path}" is not a valid directory.', + throw new CException(Yii::t('yii:CHttpSession.savePath "{path}" is not a valid directory.', array('{path}'=>$value))); } @@ -280,7 +280,7 @@ class CHttpSession extends CApplicationComponent implements IteratorAggregate,Ar ini_set('session.use_only_cookies','1'); } else - throw new CException(Yii::t('yii','CHttpSession.cookieMode can only be "none", "allow" or "only".')); + throw new CException(Yii::t('yii:CHttpSession.cookieMode can only be "none", "allow" or "only".')); } /** @@ -304,7 +304,7 @@ class CHttpSession extends CApplicationComponent implements IteratorAggregate,Ar ini_set('session.gc_divisor','100'); } else - throw new CException(Yii::t('yii','CHttpSession.gcProbability "{value}" is invalid. It must be an integer between 0 and 100.', + throw new CException(Yii::t('yii:CHttpSession.gcProbability "{value}" is invalid. It must be an integer between 0 and 100.', array('{value}'=>$value))); }