Change the translation path for the Symfony 2 validator

By default, the translation domain for the Symfony 2 validator is ‘validators’ and the translations are stored in the resources/translations/validators.<locale>.xliff files. In some applications it might be nice to use the same translation file as the rest of the site translations for validation messages, rather than using a separate validation translation file. Symfony makes this easy by setting a single parameter.

Lets say we want our translated validation messages for the AcmeStoreBundle’s to be stored in the messages.<locale>.xliff files instead of the validators.<locale> files. To do this we simply need to set the validators translation domain.


Add the following to your parameters.yml file:

# app/config/parameters.yml

    validator.translation_domain: messages


After we add the translation domain parameter the validator will check the src/Acme/StoreBundle/Resources/translations/messages.<locale>.xliff file for a translation instead of the src/Acme/StoreBundle/Resources/translations/validators.<locale>.xliff file.

4 comments on “Change the Symfony 2 Validator Translation Domain and File Path

  1. Nichol says:

    I need to to thank you for this very good read!! I absolutely enjoyed every little bit
    of it. I have got you book marked to look at new
    stuff you post…

  2. Magdalena says:

    Woah! I’m really digging the template/theme of this site.
    It’s simple, yet effective. A lot of times it’s tough to get that
    “perfect balance” between superb usability and visual appeal.

    I must say you’ve done a fantastic job with this. Additionally, the blog loads very quick for me on Chrome.
    Outstanding Blog!

  3. Valentas says:

    Actually there is no need to override a symfony parameter.
    Just configure following in config.yml:

    translation_domain: messages

  4. vbourdeix says:

    Please note that if you use the JMSSerializerBundle you will have to override the parameter ‘jms_serializer.form_error_handler.class’ with a custom class of yours, because the default class forces the translation domain to ‘validators’ for error messages.

Comments are closed.