Browse Source

Improved plural messages for validators

tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
e14cac638a
  1. 6
      framework/yii/validators/FileValidator.php
  2. 8
      framework/yii/validators/ImageValidator.php
  3. 6
      framework/yii/validators/StringValidator.php

6
framework/yii/validators/FileValidator.php

@ -107,16 +107,16 @@ class FileValidator extends Validator
$this->uploadRequired = Yii::t('yii', 'Please upload a file.'); $this->uploadRequired = Yii::t('yii', 'Please upload a file.');
} }
if ($this->tooMany === null) { if ($this->tooMany === null) {
$this->tooMany = Yii::t('yii', 'You can upload at most {limit} files.'); $this->tooMany = Yii::t('yii', 'You can upload at most {limit, number} {limit, plural, one{file} other{files}}.');
} }
if ($this->wrongType === null) { if ($this->wrongType === null) {
$this->wrongType = Yii::t('yii', 'Only files with these extensions are allowed: {extensions}.'); $this->wrongType = Yii::t('yii', 'Only files with these extensions are allowed: {extensions}.');
} }
if ($this->tooBig === null) { if ($this->tooBig === null) {
$this->tooBig = Yii::t('yii', 'The file "{file}" is too big. Its size cannot exceed {limit} bytes.'); $this->tooBig = Yii::t('yii', 'The file "{file}" is too big. Its size cannot exceed {limit, number} {limit, plural, one{byte} other{bytes}}.');
} }
if ($this->tooSmall === null) { if ($this->tooSmall === null) {
$this->tooSmall = Yii::t('yii', 'The file "{file}" is too small. Its size cannot be smaller than {limit} bytes.'); $this->tooSmall = Yii::t('yii', 'The file "{file}" is too small. Its size cannot be smaller than {limit, number} {limit, plural, one{byte} other{bytes}}.');
} }
if (!is_array($this->types)) { if (!is_array($this->types)) {
$this->types = preg_split('/[\s,]+/', strtolower($this->types), -1, PREG_SPLIT_NO_EMPTY); $this->types = preg_split('/[\s,]+/', strtolower($this->types), -1, PREG_SPLIT_NO_EMPTY);

8
framework/yii/validators/ImageValidator.php

@ -120,16 +120,16 @@ class ImageValidator extends FileValidator
$this->notImage = Yii::t('yii', 'The file "{file}" is not an image.'); $this->notImage = Yii::t('yii', 'The file "{file}" is not an image.');
} }
if ($this->underWidth === null) { if ($this->underWidth === null) {
$this->underWidth = Yii::t('yii', 'The file "{file}" is too small. The width cannot be smaller than {limit} pixels.'); $this->underWidth = Yii::t('yii', 'The file "{file}" is too small. The width cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.');
} }
if ($this->underHeight === null) { if ($this->underHeight === null) {
$this->underHeight = Yii::t('yii', 'The file "{file}" is too small. The height cannot be smaller than {limit} pixels.'); $this->underHeight = Yii::t('yii', 'The file "{file}" is too small. The height cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.');
} }
if ($this->overWidth === null) { if ($this->overWidth === null) {
$this->overWidth = Yii::t('yii', 'The file "{file}" is too large. The width cannot be larger than {limit} pixels.'); $this->overWidth = Yii::t('yii', 'The file "{file}" is too large. The width cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.');
} }
if ($this->overHeight === null) { if ($this->overHeight === null) {
$this->overHeight = Yii::t('yii', 'The file "{file}" is too large. The height cannot be larger than {limit} pixels.'); $this->overHeight = Yii::t('yii', 'The file "{file}" is too large. The height cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.');
} }
if ($this->wrongMimeType === null) { if ($this->wrongMimeType === null) {
$this->wrongMimeType = Yii::t('yii', 'Only files with these mimeTypes are allowed: {mimeTypes}.'); $this->wrongMimeType = Yii::t('yii', 'Only files with these mimeTypes are allowed: {mimeTypes}.');

6
framework/yii/validators/StringValidator.php

@ -84,13 +84,13 @@ class StringValidator extends Validator
$this->message = Yii::t('yii', '{attribute} must be a string.'); $this->message = Yii::t('yii', '{attribute} must be a string.');
} }
if ($this->min !== null && $this->tooShort === null) { if ($this->min !== null && $this->tooShort === null) {
$this->tooShort = Yii::t('yii', '{attribute} should contain at least {min} characters.'); $this->tooShort = Yii::t('yii', '{attribute} should contain at least {min, number} {min, plural, one{character} other{characters}}.');
} }
if ($this->max !== null && $this->tooLong === null) { if ($this->max !== null && $this->tooLong === null) {
$this->tooLong = Yii::t('yii', '{attribute} should contain at most {max} characters.'); $this->tooLong = Yii::t('yii', '{attribute} should contain at most {max, number} {max, plural, one{character} other{characters}}.');
} }
if ($this->length !== null && $this->notEqual === null) { if ($this->length !== null && $this->notEqual === null) {
$this->notEqual = Yii::t('yii', '{attribute} should contain {length} characters.'); $this->notEqual = Yii::t('yii', '{attribute} should contain {length, number} {length, plural, one{character} other{characters}}.');
} }
} }

Loading…
Cancel
Save