简体   繁体   English

Symfony2:相同树枝视图的局部更改

[英]Symfony2: local changes for same twig view

I've implemented the Jmsi18nRountingBundle in my symfony2 application : symfony2: how to parameter localization so we can have 2 languages? 我已经在我的symfony2应用程序中实现了Jmsi18nRountingBundle: symfony2:如何参数化本地化以便我们可以使用2种语言?

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. 我以为是这样,但是现在我开始进行一些翻译,我意识到,用于翻译由树枝中的trans标签包围的文本的语言环境在单个模板中有所不同。

See the ouput of the profiler : 参见分析器的输出:

在此处输入图片说明

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 : 我有两个翻译文件,header.fr.xlf和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: 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: 编辑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. 如果将优先级设置为17,则语言环境对于模板保持不变。 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. 这是因为存在一个优先级为10的转换侦听器,该侦听器会使用针对该语言环境的请求默认值来更改语言环境,该默认值实际上是由语言环境侦听器通过读取会话值来设置的。

I still have different locales for a given template and the one generated with render(controller())... investigating this. 对于给定的模板和使用render(controller())生成的模板,我仍然具有不同的语言环境。

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. 除了向我的区域设置侦听器添加优先级17之外,我还想确保它也可以处理子请求。

See the corrected code here : symfony2: how to parameter localization so we can have 2 languages? 在这里查看更正后的代码: symfony2:如何参数化本地化,以便我们可以使用2种语言?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM