Charles
Charles

Reputation: 11758

symfony how to translate form error message

Does anyone know how to translate form error messages in Symfony ?

At the moment I write this line in the configure() of the form:

sfContext::getInstance()->getConfiguration()->loadHelpers(array('I18N'));

And then I overwrite all error messages with the __() method.

Is there any way for Symfony to translate error messages without calling a helper and overwriting error messages ?

Upvotes: 0

Views: 3282

Answers (1)

Grad van Horck
Grad van Horck

Reputation: 4506

How I do it:

Add to the configure function of the Form to following line:

$this->widgetSchema->getFormFormatter()->setTranslationCatalogue('forms');

Then create a translation file like: \i18n\forms.nl.xml (in your application root or the plugin root)

It's also possible to add translations for the default validators (like 'Required.', etc.)

Upvotes: 4

Related Questions