beberlei / assert

Thin assertion library for use in libraries and business-model
Other
2.41k stars 188 forks source link

localization question #225

Open romaninsh opened 7 years ago

romaninsh commented 7 years ago

Just curious, what is the best way to localize this method:

https://github.com/beberlei/assert/blob/master/lib/Assert/Assertion.php#L2558

rquadling commented 7 years ago

You can override the method in your own subclass, or you can provide a callback with each assertion.

But it would probably be better to provide your own Exception class that will generate an appropriate message based upon the exception code.

romaninsh commented 7 years ago

This wouldn't work with default messages though:

https://github.com/beberlei/assert/blob/master/lib/Assert/Assertion.php#L2543

$message = \sprintf(static::generateMessage($message) ?: 'Value "%s" expected to be a defined constant.', $constant);

while something like this would work:

$message = \sprintf(static::generateMessage($message ?: 'Value "%s" expected to be a defined constant.'), $constant);

any ideas?