在FOSUserBundle中添加新的电子邮件翻译[英] Adding new email translation in FOSUserBundle

本文是小编为大家收集整理的关于在FOSUserBundle中添加新的电子邮件翻译的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我在fosuserbundle中添加了一个新的翻译字段,电子邮件,如下:

security:
    login:
        email: Email
        username: Username
        password: Password
        remember_me: Remember me
        submit: Log in

所有翻译文件都在src/UserBundle/Resources/translations中. 我的login.html.twig文件看起来像:

{% extends "UserBundle::layout.html.twig" %}

{% trans_default_domain 'FOSUserBundle' %}

{% block fos_user_content %}
{% if error %}
    <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}

<form action="{{ path("fos_user_security_check") }}" method="post">
    <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

    <label for="email">{{ 'security.login.email'|trans }}</label>
    <input type="email" id="email" name="_email" value="{{ last_username }}" required="required" />

    <label for="password">{{ 'security.login.password'|trans }}</label>
    <input type="password" id="password" name="_password" required="required" />

    <input type="checkbox" id="remember_me" name="_remember_me" value="on" />
    <label for="remember_me">{{ 'security.login.remember_me'|trans }}</label>

    <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans }}" />
</form>
{% endblock fos_user_content %}

但是,当我加载登录页面时,电子邮件字段未翻译.发生了什么?

推荐答案

我也有一些自定义的翻译 - 我复制的文件,然后覆盖它们是app/Resources/FOSUserBundle/translations/FOSUserBundle.en.yml.

本文地址:https://www.itbaoku.cn/post/2090846.html

问题描述

I have add a new translation field, email ,in FOSUserBundle as follows:

security:
    login:
        email: Email
        username: Username
        password: Password
        remember_me: Remember me
        submit: Log in

All the translation files are in src/UserBundle/Resources/translations. My login.html.twig file looks like:

{% extends "UserBundle::layout.html.twig" %}

{% trans_default_domain 'FOSUserBundle' %}

{% block fos_user_content %}
{% if error %}
    <div>{{ error.messageKey|trans(error.messageData, 'security') }}</div>
{% endif %}

<form action="{{ path("fos_user_security_check") }}" method="post">
    <input type="hidden" name="_csrf_token" value="{{ csrf_token }}" />

    <label for="email">{{ 'security.login.email'|trans }}</label>
    <input type="email" id="email" name="_email" value="{{ last_username }}" required="required" />

    <label for="password">{{ 'security.login.password'|trans }}</label>
    <input type="password" id="password" name="_password" required="required" />

    <input type="checkbox" id="remember_me" name="_remember_me" value="on" />
    <label for="remember_me">{{ 'security.login.remember_me'|trans }}</label>

    <input type="submit" id="_submit" name="_submit" value="{{ 'security.login.submit'|trans }}" />
</form>
{% endblock fos_user_content %}

But when I load the login page the email field is not translated. What is going on?

推荐答案

I've also got some customised translations - the file where I copied and have then overridden them is app/Resources/FOSUserBundle/translations/FOSUserBundle.en.yml.