0
votes

I've implemented the Jmsi18nRountingBundle in my symfony2 application : symfony2: how to parameter localization so we can have 2 languages?

I thought it was it but now that I have started making some translations, I realize that the locale used to translate the text surrounded by the trans tag in twig varies in a single template.

See the ouput of the profiler :

enter image description here

Any idea of what might be causing this ?

In my template, I have the following code:

{# src/FoodMeUp/CoreBundle/Resources/views/Default/header.html.twig #}
{% trans_default_domain 'header' %}

<header>
    <section id="toprow" class="greybg">
        <ul class="wrapperext">
            <li id="startup_button">
                <a href="{{ path('cms', {'dir' : 'general', 'page' : 'startup'}) }}" class="bold align_center">{% trans %}howto{% endtrans %} <span>{% trans %}start{% endtrans %} </span><i class="fa fa-question-circle"></i></a>
            </li>
            <li id="top_row_message" class="padding-h">{{ socialButtons({url: 'home', padding: false , facebookLike : { layout : 'button_count'}, facebookShare : { layout : 'button_count'}, twitter : { count : 'horizontal'} , googleplus : { annotation: 'bubble'} }) }}</li>

        </ul>
    </section>
    <section id="header_content" class="padding-v whitebg clearfix">

            <div id="pres" class="wrapper fmu_flex space-between center">
                <h2 class="align_left">{% trans %}description.left.normal{% endtrans %} <strong>{% trans %}description.left.strong{% endtrans %}</strong>...</h2>
                <a id="logo" href="{{ path('home') }}"><img src="{{ asset('images/foodmeup_horizontal_w280.png') }}" alt="logo Foodmeup" class="margin-auto block"></a>
                <h2 class="align_right">...{% trans %}description.right.normal{% endtrans %} <strong>{% trans %}description.right.strong{% endtrans %}</strong> {% trans %}description.right.normal2{% endtrans %}</h2>
            </div>
            {% if isAuthenticated() == false %}
                <div id="create_account_button" class="wrapper align_center"><a href="{{ path('fos_user_security_login') }}" class="btn btn-default btn-xs">{% trans %}create.account{% endtrans %}</a></div>
            {% endif %}
    </section>

</header>

and I have two files for my translations, header.fr.xlf and header.en.xlf : en :

howto: 'How to'
start: 'start'
connect: 'Connect'
description.left.normal: 'FoodMeUp is a platform of'
description.left.strong: 'services'
description.right.normal: 'dedicated to'
description.right.strong: 'professionals'
description.right.normal2: 'of the food industry'
create.account: 'Create your account in one minute'

fr:

start: 'démarrer'
howto: 'Comment'
connect: 'Connexion'
description.left.normal: 'FoodMeUp est une plateforme de'
description.left.strong: 'services'
description.right.normal: 'dédiée aux'
description.right.strong: 'professionnels'
description.right.normal2: 'des métiers de bouche'
create.account: 'Créez votre compte en 1 minute'

EDIT 1:

I have figured out this might be a priority issue of my locale listener. If I set the priority to 17, then the locale stays the same for the template. This is because there is a translation listener of priority 10 which changes the locale with the request default value for the locale, which is actually set by the locale listener by reading the session value.

I still have different locales for a given template and the one generated with render(controller())... investigating this.

1

1 Answers

0
votes

Found the solution, ouf, this is what follows my edit.

In addition to adding a priority of 17 to my locale listener,I neeeded to make sure it also handled subrequests.

See the corrected code here : symfony2: how to parameter localization so we can have 2 languages?