0

使用symfony2.1。

我确实在 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');
}

在 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>

字段 invalid_message 将被翻译,而不是字段 email.placeholder。有错误吗?我不使用树枝并进行正常渲染。

4

1 回答 1

4

翻译后的错误消息会像您做的那样进入您的 validators.LANG.yml。但是其他所有内容都需要进入您的messages.LANG.yml

另外,我对您如何格式化 yml 感到有些困惑。通常你会这样写:

email:
    placeholder: Enter email.

register:
    password:
        repeat: Passwords don't match
于 2013-02-02T13:40:48.430 回答