首页 > 解决方案 > Symfony4:不应用验证约束翻译

问题描述

语境

我正在开发一个带有 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

在此处输入图像描述

标签: symfonysymfony4orocrm

解决方案


这似乎是因为 OroPlatform 有自己的命令行来更新翻译。

这是我的工作配置:

# /translations/validators.fr_FR.yml
This value should not be blank.: Cette valeur ne doit pas être vide

然后,我运行这些命令:php bin/console clear:cachephp bin/console oro:translation:dump

现在我可以看到我更新的翻译。


推荐阅读