繁体   English   中英

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

[英]Symfony2: local changes for same twig view

我已经在我的symfony2应用程序中实现了Jmsi18nRountingBundle: symfony2:如何参数化本地化以便我们可以使用2种语言?

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

参见分析器的输出:

在此处输入图片说明

任何可能是什么原因的想法?

在我的模板中,我有以下代码:

{# 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>

我有两个翻译文件,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:

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'

编辑1:

我发现这可能是我的区域设置侦听器的优先级问题。 如果将优先级设置为17,则语言环境对于模板保持不变。 这是因为存在一个优先级为10的转换侦听器,该侦听器会使用针对该语言环境的请求默认值来更改语言环境,该默认值实际上是由语言环境侦听器通过读取会话值来设置的。

对于给定的模板和使用render(controller())生成的模板,我仍然具有不同的语言环境。

找到了解决方案,这就是我的修改。

除了向我的区域设置侦听器添加优先级17之外,我还想确保它也可以处理子请求。

在这里查看更正后的代码: symfony2:如何参数化本地化,以便我们可以使用2种语言?

暂无
暂无

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

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