Symfony 2消息翻译

时间:2013-06-22 12:01:05

标签: php symfony

在我提出这个问题之前,我已经在stackoverflow上仔细检查了很多类似的问题,但是还是没有解决它。

任务是使用俄语消息而不是英语。让我们假设在众所周知的身份验证失败消息“Bad credentials”的情况下。所以这就是我所做的。

在我的配置中:

translator:      { fallback: en }
default_locale:  ru

创建messages.ru.xliff

<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="en" datatype="plaintext" original="file.ext">
        <body>
            <trans-unit id="1">
                <source>Bad credentials</source>
                <target>My russian variant here</target>
            </trans-unit>
        </body>
    </file>
</xliff>

最后,在我的login.html.twig中:

{% if error %}
<div class="error">{{ error.message | trans }}</div>
{% endif %}

当身份验证失败时,我仍然会继续收到“Bad credentials”消息。我试图清除缓存,但它没有帮助。

也许我错过了什么。任何帮助赞赏。感谢。

1 个答案:

答案 0 :(得分:1)

我想问题是因为您将源转换指定为“错误凭据”,但您使用“error.message”作为转换器的输入。所以你的messages.ru.xliff看起来应该更像:

<?xml version="1.0"?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
    <file source-language="en" datatype="plaintext" original="file.ext">
        <body>
            <trans-unit id="1">
                <source>error.message</source>
                <target>My russian variant here</target>
            </trans-unit>
        </body>
    </file>
</xliff>

或更改模板中的邮件标签:

{% if error %}
<div class="error">{{ "Bad credentials" | trans }}</div>
{% endif %}
相关问题