Comments (6)
(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 ($e->translateUsing('gettext');
) or Zend_Translate ($e->translateUsing(array($zendTranslate, '_'));
).
Once that support is built, the next step would be to distribute the translated messages alongside the project's code.
from validation.
I'm testing some stuff about i18n.
Which is better?
Translate the message before format? I think that can be a problem because of {{variable style}} but is the most correct.
Translate after format can return unexpected results, changing {{name}} incorrectly.
In any case, messages need to change to anything like _('{{name}} must be a valid date'), right?
from validation.
I believe the better solution is to translate the template itself.
{{name}} must be a valid date
would be translated to {{name}} deve ser uma data válida
, for example.
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!
from validation.
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
\-Essas 2 regras devem ser seguidas para "jeanpimentel"
|-"jeanpimentel" deve ser um número inteiro
\-"jeanpimentel" deve ser um número ímpar
This isn't the correct and final mode. I'm just reporting the status of this feature.
from validation.
Seems nice! I'd love to see the code, do you have it on your fork?
from validation.
from validation.
Related Issues (20)
- Respect\Stringifier\stringify() undefined function HOT 1
- Given a multirule validator, is there a usage pattern for testing a single rule? HOT 1
- ~~Why does v::containsAny(array('mod'))->validate('mode') return true?~~ Because the expected functionality is confused with In ( https://respect-validation.readthedocs.io/en/latest/rules/In/ ) HOT 1
- messages translate HOT 1
- define different error messages HOT 2
- Is there a roadmap or future plan for this repository? HOT 10
- filterVal not correct working with FILTER_VALIDATE_INT HOT 1
- CountryCode validation for Montenegro HOT 2
- IntVal: ctype_digit gives a deprecated notice in PHP 8.1 HOT 3
- ctype_digit deprecation notice HOT 1
- Release 2.2.4 HOT 2
- Roadmap to 2.3 HOT 13
- Code coverage in local environment HOT 2
- [documentaiton] Validation for a full array of data HOT 3
- Formatter inconsequently stringifies values HOT 6
- IBAN Validation with non-breaking spaces HOT 1
- How do custom validation rules throw custom error messages? HOT 2
- How to compare two field HOT 1
- DateTime validation fails on valid ISO-8601 timestamp HOT 1
- phone() validation incorrectly invalidates valid UK phone numbers HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from validation.