Search code examples
phpsymfonysymfony-3.2

Extending FosUserBundle's translations: some extra messages on extended templates does not get translated


On my Symfony 3.2 project I extended the FosUserBundle's on a file named messages.en.yml that has the following content:

security.login.username: "Username"
security.login.password: "Password"
security.login.remember_me: "Remember me"
security.login.submit: "Login"
registration.confirmed.header: "Registration Success"
reset.password.header: "Reset your password"

Please keep in note that the registration.confirmed.header and reset.password.header are used in the template that I extend from fos user bundle such as the request.html.twig that has the following content:

{% extends "@FOSUser/layout.html.twig" %}

{% set body_css_classes="skin-blue layout-top-nav" %}

{% trans_default_domain 'FOSUserBundle' %}

{% block title %} Set a new Password {% endblock %}

{% block fos_user_content %}
<div class="content-wrapper" style="min-height:100%">
        <div class="container">
            <section class="content">
                <div class="box box-default">
                    <div class="box-header">
                        <h4 class="text-center">{{ 'reset.password.header'|trans }}</h4>
                    </div>
                    <form action="{{ path('fos_user_resetting_send_email') }}" method="POST" class="form-horizontal">
                        <div class="box-body">
                          <div class="form-group">
                                    <label for="username" class="col-sm-3 control-label">{{ 'resetting.request.username'|trans }}</label>
                                    <div class="col-sm-9">
                                        <input type="text" id="username" class="form-control" name="username" required="required" />
                                    </div>
                           </div>
                           <div class="form-group">
                             <div class="col-sm-offset-3 col-sm-9">
                               <input type="submit" class="btn btn-primary" value="{{ 'resetting.request.submit'|trans }}" />
                             </div>
                           </div>
                        </div>
                    </form>
                </div>
            </section>
        </div>
    </div>
{% endblock fos_user_content %}

{% block javascriptsFooter %}
{% endblock %}

The problem is that everything gets translated except the reset.password.header that even though I put it into the messages.yml it still does not translate the extra messages I set.


Solution

  • {% trans_default_domain 'FOSUserBundle' %}
    

    This means, that the translator is not looking in the domain "messages" but "FOSUserBundle". Adding the translations in /app/Resources/translations/FOSUserBundle.en.yml should work.