doupu9251 2016-03-21 10:44
浏览 35

转换约束将数组转换为字符串转换

I am trying to translate my own constraint messages defined in validation.yml. I have something like this:

Adviser\WebServicesBundle\Entity\Messages:
    problem:
            - Type:
                type: string
            - NotBlank: ~
            - Length:
                min: 2
                max: 1000
                minMessage: { message: 'author' }

I need to translate the tag minMessage, it works fine if I put a text directly. I have a file named validators.es.yml inside the directory "Resources/translation" where is located the translation message:

author: "Message too short"

I also have proved using a xlf format adding the following content overriding the file validators.es.xlf:

<trans-unit id="81">
            <source>author</source>
            <target>Message too short</target>
</trans-unit>

I get the same error in both cases, "Array to string conversion" when I submit the form to force the message. This is the piece of code which throws the exception:

     $domain = 'messages';
    }
    $id = (string) $id;
    $catalogue = $this->getCatalogue($locale);
    $locale = $catalogue->getLocale();
    while (!$catalogue->defines($id, $domain)) {

I have followed carefully this documentation with no success http://symfony.com/doc/2.7/book/translation.html#translating-constraint-messages

I am currently working with symfony 2.7 and any other translations work fine throughout the whole project. I just have this problem with own constraint messages, I don't understand why the validation.yml file can't get the defined messages. Is there a way to achieve this?

  • 写回答

1条回答 默认 最新

  • duancheng8000 2016-03-21 11:37
    关注

    I can see that your translation file is different from what is in symfony documentation:

    <class name="AppBundle\Entity\Author">
        <property name="name">
            <constraint name="NotBlank">
                <option name="message">author.name.not_blank</option>
            </constraint>
        </property>
    </class>
    

    So it's simply not enough to just provide translation as usual for validation messages.

    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀