Skip to content

Commit 7d12a71

Browse files
committed
Make file size messages human-readable
1 parent 92acabd commit 7d12a71

10 files changed

Lines changed: 464 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 2.6.1 under development
44

5-
- no changes in this release.
5+
- Bug #802: Use translatable human-readable file sizes in `File` validation messages and add raw byte placeholders (@samdark)
66

77
## 2.6.0 June 02, 2026
88

docs/guide/en/built-in-rules-file.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ This option should be used with care because the client can send any media type
7979
For filesystem-backed uploads, size checks use the actual file size on disk. For pathless streams, size checks use the
8080
PSR-7 upload size when available. If a size constraint is configured and the size can't be determined, validation fails.
8181

82+
Default size error messages use translatable human-readable units, for example `50 MB` when `maxSize` is
83+
`50 * 1024 * 1024`.
84+
In custom messages, `{limit}` and `{exactly}` contain the numeric value converted to a human-readable unit, while
85+
`{limitUnit}` and `{exactlyUnit}` contain the unit identifier. Use `{limitBytes}` or `{exactlyBytes}` when a custom
86+
message needs the raw byte value for ICU number or plural formatting.
87+
8288
`size` is mutually exclusive with `minSize` and `maxSize`. When both `minSize` and `maxSize` are set, `minSize` must be
8389
less than or equal to `maxSize`.
8490

messages/de/yii-validator.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Yiisoft\Validator\Rule\Each;
1010
use Yiisoft\Validator\Rule\Email;
1111
use Yiisoft\Validator\Rule\Equal;
12+
use Yiisoft\Validator\Rule\File;
1213
use Yiisoft\Validator\Rule\FilledAtLeast;
1314
use Yiisoft\Validator\Rule\FilledOnlyOneOf;
1415
use Yiisoft\Validator\Rule\GreaterThan;
@@ -211,6 +212,44 @@
211212
/** @see AnyRule */
212213
'At least one of the inner rules must pass the validation.' => 'Mindestens eine der inneren Regeln muss die Validierung bestehen.',
213214

215+
/** @see File */
216+
'The size of {property} must be exactly {exactly, number} {exactly, plural, one{byte} other{bytes}}.' =>
217+
'Die Größe von {property} muss genau {exactly, number} {exactly, plural, one{Byte} other{Byte}} betragen.',
218+
'The size of {property} must be exactly {exactly, number} KB.' =>
219+
'Die Größe von {property} muss genau {exactly, number} KB betragen.',
220+
'The size of {property} must be exactly {exactly, number} MB.' =>
221+
'Die Größe von {property} muss genau {exactly, number} MB betragen.',
222+
'The size of {property} must be exactly {exactly, number} GB.' =>
223+
'Die Größe von {property} muss genau {exactly, number} GB betragen.',
224+
'The size of {property} must be exactly {exactly, number} TB.' =>
225+
'Die Größe von {property} muss genau {exactly, number} TB betragen.',
226+
'The size of {property} must be exactly {exactly, number} PB.' =>
227+
'Die Größe von {property} muss genau {exactly, number} PB betragen.',
228+
'The size of {property} cannot be smaller than {limit, number} {limit, plural, one{byte} other{bytes}}.' =>
229+
'Die Größe von {property} darf nicht kleiner als {limit, number} {limit, plural, one{Byte} other{Byte}} sein.',
230+
'The size of {property} cannot be smaller than {limit, number} KB.' =>
231+
'Die Größe von {property} darf nicht kleiner als {limit, number} KB sein.',
232+
'The size of {property} cannot be smaller than {limit, number} MB.' =>
233+
'Die Größe von {property} darf nicht kleiner als {limit, number} MB sein.',
234+
'The size of {property} cannot be smaller than {limit, number} GB.' =>
235+
'Die Größe von {property} darf nicht kleiner als {limit, number} GB sein.',
236+
'The size of {property} cannot be smaller than {limit, number} TB.' =>
237+
'Die Größe von {property} darf nicht kleiner als {limit, number} TB sein.',
238+
'The size of {property} cannot be smaller than {limit, number} PB.' =>
239+
'Die Größe von {property} darf nicht kleiner als {limit, number} PB sein.',
240+
'The size of {property} cannot be larger than {limit, number} {limit, plural, one{byte} other{bytes}}.' =>
241+
'Die Größe von {property} darf nicht größer als {limit, number} {limit, plural, one{Byte} other{Byte}} sein.',
242+
'The size of {property} cannot be larger than {limit, number} KB.' =>
243+
'Die Größe von {property} darf nicht größer als {limit, number} KB sein.',
244+
'The size of {property} cannot be larger than {limit, number} MB.' =>
245+
'Die Größe von {property} darf nicht größer als {limit, number} MB sein.',
246+
'The size of {property} cannot be larger than {limit, number} GB.' =>
247+
'Die Größe von {property} darf nicht größer als {limit, number} GB sein.',
248+
'The size of {property} cannot be larger than {limit, number} TB.' =>
249+
'Die Größe von {property} darf nicht größer als {limit, number} TB sein.',
250+
'The size of {property} cannot be larger than {limit, number} PB.' =>
251+
'Die Größe von {property} darf nicht größer als {limit, number} PB sein.',
252+
214253
/** @see Image */
215254
'{Property} must be an image.' => '{Property} muss ein Bild sein.',
216255
'The width of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.' =>

messages/pl/yii-validator.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Yiisoft\Validator\Rule\Each;
1414
use Yiisoft\Validator\Rule\Email;
1515
use Yiisoft\Validator\Rule\Equal;
16+
use Yiisoft\Validator\Rule\File;
1617
use Yiisoft\Validator\Rule\GreaterThan;
1718
use Yiisoft\Validator\Rule\GreaterThanOrEqual;
1819
use Yiisoft\Validator\Rule\Image\Image;
@@ -63,6 +64,25 @@
6364
'{Property} is not a valid email address.' => '{Property} nie jest prawidłowym adresem e-mail.',
6465
/** @see FloatType */
6566
'{Property} must be a float.' => '{Property} musi być liczbą zmiennoprzecinkową.',
67+
/** @see File */
68+
'The size of {property} must be exactly {exactly, number} {exactly, plural, one{byte} other{bytes}}.' => 'Rozmiar {property} musi wynosić dokładnie {exactly, number} {exactly, plural, one{bajt} few{bajty} many{bajtów} other{bajta}}.',
69+
'The size of {property} must be exactly {exactly, number} KB.' => 'Rozmiar {property} musi wynosić dokładnie {exactly, number} KB.',
70+
'The size of {property} must be exactly {exactly, number} MB.' => 'Rozmiar {property} musi wynosić dokładnie {exactly, number} MB.',
71+
'The size of {property} must be exactly {exactly, number} GB.' => 'Rozmiar {property} musi wynosić dokładnie {exactly, number} GB.',
72+
'The size of {property} must be exactly {exactly, number} TB.' => 'Rozmiar {property} musi wynosić dokładnie {exactly, number} TB.',
73+
'The size of {property} must be exactly {exactly, number} PB.' => 'Rozmiar {property} musi wynosić dokładnie {exactly, number} PB.',
74+
'The size of {property} cannot be smaller than {limit, number} {limit, plural, one{byte} other{bytes}}.' => 'Rozmiar {property} nie może być mniejszy niż {limit, number} {limit, plural, one{bajt} few{bajty} many{bajtów} other{bajta}}.',
75+
'The size of {property} cannot be smaller than {limit, number} KB.' => 'Rozmiar {property} nie może być mniejszy niż {limit, number} KB.',
76+
'The size of {property} cannot be smaller than {limit, number} MB.' => 'Rozmiar {property} nie może być mniejszy niż {limit, number} MB.',
77+
'The size of {property} cannot be smaller than {limit, number} GB.' => 'Rozmiar {property} nie może być mniejszy niż {limit, number} GB.',
78+
'The size of {property} cannot be smaller than {limit, number} TB.' => 'Rozmiar {property} nie może być mniejszy niż {limit, number} TB.',
79+
'The size of {property} cannot be smaller than {limit, number} PB.' => 'Rozmiar {property} nie może być mniejszy niż {limit, number} PB.',
80+
'The size of {property} cannot be larger than {limit, number} {limit, plural, one{byte} other{bytes}}.' => 'Rozmiar {property} nie może być większy niż {limit, number} {limit, plural, one{bajt} few{bajty} many{bajtów} other{bajta}}.',
81+
'The size of {property} cannot be larger than {limit, number} KB.' => 'Rozmiar {property} nie może być większy niż {limit, number} KB.',
82+
'The size of {property} cannot be larger than {limit, number} MB.' => 'Rozmiar {property} nie może być większy niż {limit, number} MB.',
83+
'The size of {property} cannot be larger than {limit, number} GB.' => 'Rozmiar {property} nie może być większy niż {limit, number} GB.',
84+
'The size of {property} cannot be larger than {limit, number} TB.' => 'Rozmiar {property} nie może być większy niż {limit, number} TB.',
85+
'The size of {property} cannot be larger than {limit, number} PB.' => 'Rozmiar {property} nie może być większy niż {limit, number} PB.',
6686
/** @see Image */
6787
'{Property} must be an image.' => '{Property} musi być obrazem.',
6888
'The width of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.' => 'Szerokość {property} musi wynosić dokładnie {exactly, number} {exactly, plural, one{piksel} few{piksele} many{pikseli} other{piksela}}.',

messages/pt-BR/yii-validator.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Yiisoft\Validator\Rule\Each;
1010
use Yiisoft\Validator\Rule\Email;
1111
use Yiisoft\Validator\Rule\Equal;
12+
use Yiisoft\Validator\Rule\File;
1213
use Yiisoft\Validator\Rule\FilledAtLeast;
1314
use Yiisoft\Validator\Rule\FilledOnlyOneOf;
1415
use Yiisoft\Validator\Rule\GreaterThan;
@@ -188,6 +189,44 @@
188189
/** @see AnyRule */
189190
'At least one of the inner rules must pass the validation.' => 'Pelo menos uma das regras internas deve passar na validação.',
190191

192+
/** @see File */
193+
'The size of {property} must be exactly {exactly, number} {exactly, plural, one{byte} other{bytes}}.' =>
194+
'O tamanho de {property} deve ser exatamente {exactly, number} {exactly, plural, one{byte} few{bytes} many{bytes} other{bytes}}.',
195+
'The size of {property} must be exactly {exactly, number} KB.' =>
196+
'O tamanho de {property} deve ser exatamente {exactly, number} KB.',
197+
'The size of {property} must be exactly {exactly, number} MB.' =>
198+
'O tamanho de {property} deve ser exatamente {exactly, number} MB.',
199+
'The size of {property} must be exactly {exactly, number} GB.' =>
200+
'O tamanho de {property} deve ser exatamente {exactly, number} GB.',
201+
'The size of {property} must be exactly {exactly, number} TB.' =>
202+
'O tamanho de {property} deve ser exatamente {exactly, number} TB.',
203+
'The size of {property} must be exactly {exactly, number} PB.' =>
204+
'O tamanho de {property} deve ser exatamente {exactly, number} PB.',
205+
'The size of {property} cannot be smaller than {limit, number} {limit, plural, one{byte} other{bytes}}.' =>
206+
'O tamanho de {property} não pode ser menor que {limit, number} {limit, plural, one{byte} few{bytes} many{bytes} other{bytes}}.',
207+
'The size of {property} cannot be smaller than {limit, number} KB.' =>
208+
'O tamanho de {property} não pode ser menor que {limit, number} KB.',
209+
'The size of {property} cannot be smaller than {limit, number} MB.' =>
210+
'O tamanho de {property} não pode ser menor que {limit, number} MB.',
211+
'The size of {property} cannot be smaller than {limit, number} GB.' =>
212+
'O tamanho de {property} não pode ser menor que {limit, number} GB.',
213+
'The size of {property} cannot be smaller than {limit, number} TB.' =>
214+
'O tamanho de {property} não pode ser menor que {limit, number} TB.',
215+
'The size of {property} cannot be smaller than {limit, number} PB.' =>
216+
'O tamanho de {property} não pode ser menor que {limit, number} PB.',
217+
'The size of {property} cannot be larger than {limit, number} {limit, plural, one{byte} other{bytes}}.' =>
218+
'O tamanho de {property} não pode ser maior que {limit, number} {limit, plural, one{byte} few{bytes} many{bytes} other{bytes}}.',
219+
'The size of {property} cannot be larger than {limit, number} KB.' =>
220+
'O tamanho de {property} não pode ser maior que {limit, number} KB.',
221+
'The size of {property} cannot be larger than {limit, number} MB.' =>
222+
'O tamanho de {property} não pode ser maior que {limit, number} MB.',
223+
'The size of {property} cannot be larger than {limit, number} GB.' =>
224+
'O tamanho de {property} não pode ser maior que {limit, number} GB.',
225+
'The size of {property} cannot be larger than {limit, number} TB.' =>
226+
'O tamanho de {property} não pode ser maior que {limit, number} TB.',
227+
'The size of {property} cannot be larger than {limit, number} PB.' =>
228+
'O tamanho de {property} não pode ser maior que {limit, number} PB.',
229+
191230
/** @see Image */
192231
'{Property} must be an image.' => '{Property} deve ser uma imagem.',
193232
'The width of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.' =>

messages/ru/yii-validator.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Yiisoft\Validator\Rule\Each;
1010
use Yiisoft\Validator\Rule\Email;
1111
use Yiisoft\Validator\Rule\Equal;
12+
use Yiisoft\Validator\Rule\File;
1213
use Yiisoft\Validator\Rule\FilledAtLeast;
1314
use Yiisoft\Validator\Rule\FilledOnlyOneOf;
1415
use Yiisoft\Validator\Rule\GreaterThan;
@@ -196,6 +197,44 @@
196197
/** @see AnyRule */
197198
'At least one of the inner rules must pass the validation.' => 'Как минимум одно из внутренних правил должно пройти валидацию.',
198199

200+
/** @see File */
201+
'The size of {property} must be exactly {exactly, number} {exactly, plural, one{byte} other{bytes}}.' =>
202+
'Размер {property} должен быть ровно {exactly, number} {exactly, plural, one{байт} few{байта} many{байтов} other{байта}}.',
203+
'The size of {property} must be exactly {exactly, number} KB.' =>
204+
'Размер {property} должен быть ровно {exactly, number} КБ.',
205+
'The size of {property} must be exactly {exactly, number} MB.' =>
206+
'Размер {property} должен быть ровно {exactly, number} МБ.',
207+
'The size of {property} must be exactly {exactly, number} GB.' =>
208+
'Размер {property} должен быть ровно {exactly, number} ГБ.',
209+
'The size of {property} must be exactly {exactly, number} TB.' =>
210+
'Размер {property} должен быть ровно {exactly, number} ТБ.',
211+
'The size of {property} must be exactly {exactly, number} PB.' =>
212+
'Размер {property} должен быть ровно {exactly, number} ПБ.',
213+
'The size of {property} cannot be smaller than {limit, number} {limit, plural, one{byte} other{bytes}}.' =>
214+
'Размер {property} не может быть меньше {limit, number} {limit, plural, one{байта} few{байтов} many{байтов} other{байта}}.',
215+
'The size of {property} cannot be smaller than {limit, number} KB.' =>
216+
'Размер {property} не может быть меньше {limit, number} КБ.',
217+
'The size of {property} cannot be smaller than {limit, number} MB.' =>
218+
'Размер {property} не может быть меньше {limit, number} МБ.',
219+
'The size of {property} cannot be smaller than {limit, number} GB.' =>
220+
'Размер {property} не может быть меньше {limit, number} ГБ.',
221+
'The size of {property} cannot be smaller than {limit, number} TB.' =>
222+
'Размер {property} не может быть меньше {limit, number} ТБ.',
223+
'The size of {property} cannot be smaller than {limit, number} PB.' =>
224+
'Размер {property} не может быть меньше {limit, number} ПБ.',
225+
'The size of {property} cannot be larger than {limit, number} {limit, plural, one{byte} other{bytes}}.' =>
226+
'Размер {property} не может быть больше {limit, number} {limit, plural, one{байта} few{байтов} many{байтов} other{байта}}.',
227+
'The size of {property} cannot be larger than {limit, number} KB.' =>
228+
'Размер {property} не может быть больше {limit, number} КБ.',
229+
'The size of {property} cannot be larger than {limit, number} MB.' =>
230+
'Размер {property} не может быть больше {limit, number} МБ.',
231+
'The size of {property} cannot be larger than {limit, number} GB.' =>
232+
'Размер {property} не может быть больше {limit, number} ГБ.',
233+
'The size of {property} cannot be larger than {limit, number} TB.' =>
234+
'Размер {property} не может быть больше {limit, number} ТБ.',
235+
'The size of {property} cannot be larger than {limit, number} PB.' =>
236+
'Размер {property} не может быть больше {limit, number} ПБ.',
237+
199238
/** @see Image */
200239
'{Property} must be an image.' => '{Property} должно быть изображением.',
201240
'The width of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.' =>

messages/uz/yii-validator.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Yiisoft\Validator\Rule\Each;
1010
use Yiisoft\Validator\Rule\Email;
1111
use Yiisoft\Validator\Rule\Equal;
12+
use Yiisoft\Validator\Rule\File;
1213
use Yiisoft\Validator\Rule\FilledAtLeast;
1314
use Yiisoft\Validator\Rule\FilledOnlyOneOf;
1415
use Yiisoft\Validator\Rule\GreaterThan;
@@ -188,6 +189,44 @@
188189
/** @see AnyRule */
189190
'At least one of the inner rules must pass the validation.' => 'Ichki qoidalardan kamida bittasi tekshiruvdan oʻtishi kerak.',
190191

192+
/** @see File */
193+
'The size of {property} must be exactly {exactly, number} {exactly, plural, one{byte} other{bytes}}.' =>
194+
'{property} hajmi aynan {exactly, number} {exactly, plural, one{bayt} other{bayt}} boʻlishi kerak.',
195+
'The size of {property} must be exactly {exactly, number} KB.' =>
196+
'{property} hajmi aynan {exactly, number} KB boʻlishi kerak.',
197+
'The size of {property} must be exactly {exactly, number} MB.' =>
198+
'{property} hajmi aynan {exactly, number} MB boʻlishi kerak.',
199+
'The size of {property} must be exactly {exactly, number} GB.' =>
200+
'{property} hajmi aynan {exactly, number} GB boʻlishi kerak.',
201+
'The size of {property} must be exactly {exactly, number} TB.' =>
202+
'{property} hajmi aynan {exactly, number} TB boʻlishi kerak.',
203+
'The size of {property} must be exactly {exactly, number} PB.' =>
204+
'{property} hajmi aynan {exactly, number} PB boʻlishi kerak.',
205+
'The size of {property} cannot be smaller than {limit, number} {limit, plural, one{byte} other{bytes}}.' =>
206+
'{property} hajmi {limit, number} {limit, plural, one{bayt} other{bayt}}dan kichik boʻlishi mumkin emas.',
207+
'The size of {property} cannot be smaller than {limit, number} KB.' =>
208+
'{property} hajmi {limit, number} KBdan kichik boʻlishi mumkin emas.',
209+
'The size of {property} cannot be smaller than {limit, number} MB.' =>
210+
'{property} hajmi {limit, number} MBdan kichik boʻlishi mumkin emas.',
211+
'The size of {property} cannot be smaller than {limit, number} GB.' =>
212+
'{property} hajmi {limit, number} GBdan kichik boʻlishi mumkin emas.',
213+
'The size of {property} cannot be smaller than {limit, number} TB.' =>
214+
'{property} hajmi {limit, number} TBdan kichik boʻlishi mumkin emas.',
215+
'The size of {property} cannot be smaller than {limit, number} PB.' =>
216+
'{property} hajmi {limit, number} PBdan kichik boʻlishi mumkin emas.',
217+
'The size of {property} cannot be larger than {limit, number} {limit, plural, one{byte} other{bytes}}.' =>
218+
'{property} hajmi {limit, number} {limit, plural, one{bayt} other{bayt}}dan katta boʻlishi mumkin emas.',
219+
'The size of {property} cannot be larger than {limit, number} KB.' =>
220+
'{property} hajmi {limit, number} KBdan katta boʻlishi mumkin emas.',
221+
'The size of {property} cannot be larger than {limit, number} MB.' =>
222+
'{property} hajmi {limit, number} MBdan katta boʻlishi mumkin emas.',
223+
'The size of {property} cannot be larger than {limit, number} GB.' =>
224+
'{property} hajmi {limit, number} GBdan katta boʻlishi mumkin emas.',
225+
'The size of {property} cannot be larger than {limit, number} TB.' =>
226+
'{property} hajmi {limit, number} TBdan katta boʻlishi mumkin emas.',
227+
'The size of {property} cannot be larger than {limit, number} PB.' =>
228+
'{property} hajmi {limit, number} PBdan katta boʻlishi mumkin emas.',
229+
191230
/** @see Image */
192231
'{Property} must be an image.' => '{Property} rasm boʻlishi kerak.',
193232
'The width of {property} must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.' =>

0 commit comments

Comments
 (0)