drhdjp97757 2015-06-16 13:54
浏览 48

Symfony2:相同树枝视图的本地更改

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条回答 默认 最新

  • duankuan5319 2015-06-16 15:20
    关注

    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?

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题