Language / Validation messages
elliotlewis opened this issue · 4 comments
Great package.
I'm using the English Language file but I'd like to change some of the validation messages just so it reads differently.
I was hoping to do this using $form->addConstraint()* but it makes more sense to overwrite the whole language file. I don't want to edit the repo, so is there a way to pick a custom language file that's in my app?
- This also doesn't work, as it doesn't overwrite the internal validation :(
Hello,
You could inherit your own class from Gregwar\Formidable\Language\English
and change messages in the constructor:
<?php
class CustomLanguage extends Gregwar\Formidable\Language\English {
public function __construct() {
$this->messages["read_only"] = "The field %s is read only!!";
}
}
And then:
<?php
$form->setLangage(new CustomLanguage);
Thanks. That would work well. I'm now having problems with:
PHP Fatal error: Class 'Gregwar\Formidable\Language\Gregwar\Formidable\Language\English' not found in CustomEnglish.php on line 5
As everything is loaded with composers autoload I'm not sure how to get this working with the correct namespaces. I've tried use
. Sorry if this is a dumb question.
I forgot the prefix \ in my example, and you should rather do:
<?php
use Gregwar\Formidable\Language\English;
class CustomLanguage extends English {
public function __construct() {
$this->messages["read_only"] = "The field %s is read only!!";
}
}
That's working, thanks for the help.
BTW: there's a spelling mistake in your first solution:
$form->setLangage(new CustomLanguage);
Should be:
$form->setLang**u**age(new CustomLanguage);