Symfony2 从实体注释翻译断言消息 [英] Symfony2 Translate Assertion message from entity annotation
问题描述
我有一个带有一些验证和断言消息的实体.我需要将这些信息翻译成阿拉伯语我有一个messages.ar.xlf文件来自实体的验证消息未翻译!
I have an entity with some validation and assertion messages. I need to translate that messages into arabic i have a messages.ar.xlf file The validation message from the Entity is not translated!
<trans-unit id="1">
<source>Enter.Car.Details</source>
<target>بيانات السيارة</target>
</trans-unit>
这是我的实体
/**
* @var string
* @Assert\Length(max = "4", maxMessage = "Enter.Car.Details")
* @Assert\NotBlank(message="Enter.Car.Details")
* @ORM\Column(name="year_made", type="integer", length=4, nullable=true)
*/
private $yearMade;
这是我的 config.yml
and here's my config.yml
framework:
translator: { fallback: ar }
注意:- 我在我的 twig 文件中翻译了一些单词,以检查本地文件和 messages.ar.xlf 文件是否正常工作,除了来自实体的验证消息外,其他一切都在工作.
Note :- I translated some words in my twig file to check if the local and messages.ar.xlf file are working or not, and it's all working except the validation messages coming from the Entity.
推荐答案
验证消息不是来自 messages
域,而是来自 validators
域.
The validation messages are get not from messages
domain, but from validators
one.
因此创建 validators.ar.xlf
文件并将您的验证消息放在那里并且应该可以工作(请参阅 Symfony2 官方文档供参考).
So create validators.ar.xlf
file and put your validation messages there and should be working (see the official Symfony2 documentation for reference).
还有一件事.取决于您使用的 Symfony 版本: maxLength
断言 id 从 Symfony 2.1 中弃用,并在 2.3 中删除.所以,如果你使用 Symfony >2.0,那么你应该使用 Length
断言.
One more thing. Depending on what Symfony version do you use: maxLength
assertion id deprecated from Symfony 2.1 and is removed in 2.3. So, if you use Symfony >2.0, then you should use Length
assertion instead.
这篇关于Symfony2 从实体注释翻译断言消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!