New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I18n #28
Comments
(sorry for closing the issue, that wasn't intentional) There's nothing done yet on i18n. The messages are built only when you request them, and its possible to use an iterator to traverse and translate them: <?php
$translator = new TranslatorFooBar();
try {
v::email()->assert('invalid@');
} catch (ValidationException $e) {
foreach ($e->getIterator() as $child)
$child->setTemplate($translator->translate($child->getTemplate());
} I'm not sure if a built-in translator is a good idea. Maybe is too much for the project itself, but for sure translation support is welcome. Since several translating engines relies on messaging lookup (gettext style) I think something like this would be welcome: <?php
$translatorCallback = new Anything;
try {
v::email()->assert('invalid@');
} catch (ValidationException $e) {
$e->translateUsing($translatorCallback);
$messages = $e->findMessages(/* ... */);
} This would allow users to use any translating engine they want. For example, built-in PHP's gettext ( Once that support is built, the next step would be to distribute the translated messages alongside the project's code. |
I'm testing some stuff about i18n. |
I believe the better solution is to translate the template itself.
Each ValidationException instance (and its descendants) has getTemplate() and setTemplate() methods that we could use in a possible I18n module. If you have any samples on the I18n API you're working on I'd be happy to take a look! |
After some attempts, this is a draft that works: try {
v::translateCallback(array('MyTranslate', 'translate'))->int()->max(30)->odd()->assert('jeanpimentel');
} catch (\Respect\Validation\Exceptions\ValidationException $e) {
echo $e->getFullMessage();
} Results
This isn't the correct and final mode. I'm just reporting the status of this feature. |
Seems nice! I'd love to see the code, do you have it on your fork? |
Is there any plan to this?
How could I translate errors?
to
The text was updated successfully, but these errors were encountered: