craphunter
craphunter

Reputation: 981

Translation in form placeholder

Using symfony2.1.

I do build a form in Form/RegisterUser.php

public function buildForm(FormBuilderInterface $builder, array $options) {
    $builder->add(
        'email',
        'email',
        array('attr' => array('placeholder' => 'email.placeholder')));
    $builder->add(
        'password',
        'repeated',
        array(
            'first_name' => 'password',
            'second_name' => 'confirm',
            'type' => 'password',
            'invalid_message' => 'register.password.repeat', ));
    $builder->add("t_and_c", "checkbox", array("mapped" => false, ));

    // "True" validator on the form for t&c
    $builder->addValidator(new CallbackValidator( function(FormInterface $form) {
        if (!$form["t_and_c"]->getData()) {
            $form->addError(new FormError('Please accept the terms and conditions in order to register'));
        }
    }));
}

/**
 * Returns the default options for this form type.
 * @param array $options
 * @return array The default options
 */
public function getDefaultOptions(array $options) {
    return array('data_class' => 'Frontend\AccountBundle\Entity\User');
}

And in app/Ressources/translation/validators.LANG.yml:

<trans-unit id="6">
    <source>email.placeholder</source>
    <target>Enter email.</target>
</trans-unit>
<trans-unit id="12">
    <source>register.password.repeat</source>
    <target>Passwords don't match.</target>
</trans-unit>

The field invalid_message is going to be translated but not the field email.placeholder. Is there a bug? I don't usw twig and do a normal render.

Upvotes: 0

Views: 3710

Answers (1)

Schwierig
Schwierig

Reputation: 712

Translated error messages go into your validators.LANG.yml like you did right. But everything else needs to go into your messages.LANG.yml.

Also I'm a bit confused by how you are formatting your yml. Normally you write it like this:

email:
    placeholder: Enter email.

register:
    password:
        repeat: Passwords don't match

Upvotes: 4

Related Questions