问题描述
上下文
我正在开发一个带有 OroPlatform 覆盖层的 Symfony 4 应用程序。
我遵循了本教程:https://symfony.com/doc/4.4/validation/translations.html
这是我的代码:
<?PHP
/**
* @ORM\Entity(repositoryClass="Baltimore\Bundle\AppBundle\Repository\SubscriptionRepository")
* @ORM\Table(name="app_subscription")
*/
class Subscription
{
/**
* @ORM\Id()
* @ORM\GeneratedValue(strategy="AUTO")
* @ORM\Column(type="integer")
*
* @var int
*/
private $id;
/**
* @ORM\Column(type="integer")
* @Assert\NotBlank(message="author.name.not_blank")
* @Assert\Type(type="integer")
*
* @var int
*/
private $number;
}
如您所见,我已将此行更改为默认 NotBlank
消息 @Assert\NotBlank(message="author.name.not_blank")
问题
我当前的语言环境是 fr_FR
,我已经检查了以下代码:
<?PHP
$locale = $request->getLocale();
这是我的 translations/validators.fr_FR.xlf
(路径是相对于项目根目录的):
<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="fr" datatype="plaintext" original="file.ext">
<body>
<trans-unit id="author.name.not_blank">
<source>author.name.not_blank</source>
<target>Veuillez entrer un nom d'auteur</target>
</trans-unit>
</body>
</file>
</xliff>
缓存被清除symfony console cache:clear
但没有任何变化,错误信息是 author.name.not_blank
而不是我的翻译。
命令行输出PHP bin/console debug:translation fr BaltimoreAppBundle
:
解决方法
似乎是因为 OroPlatform 有自己的命令行来更新翻译。
这是我的工作配置:
# /translations/validators.fr_FR.yml
This value should not be blank.: Cette valeur ne doit pas être vide
然后,我运行这些命令:php bin/console clear:cache
和 php bin/console oro:translation:dump
现在我可以看到我更新的翻译了。