简体   繁体   English

设置 symfony2 翻译

[英]Setting up symfony2 translation

I want to create translation for my app in sympfony 2. I create selector like this :我想在 sympfony 2 中为我的应用程序创建翻译。我像这样创建选择器:

<li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown">Language <b class="caret"></b></a>
            <ul class="dropdown-menu alert-dropdown">
                <li><a href="{{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': 'sr'})) }}">Serbian</a></li>
                <li><a href="{{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': 'en'})) }}">English</a></li>
            </ul>
        </li>

Now in my url i get ... ?_locale=en , also i have folder structure like :现在在我的 url 中我得到 ... ?_locale=en ,我也有文件夹结构,如:

MyAppBudnle/
-Resources
--translations
---messages.sr.yml - File with translations.

And also in mu App/config/config.yml i have this line :而且在 mu App/config/config.yml我有这一行:

framework:
    #esi:             ~
    translator:      { fallback: en }

... ...

Can you tell me now, what more i need to create so, that translation start working.你现在能告诉我,我还需要创造什么,翻译开始工作。 my app is on english, and when i change it to SR it should be on Serbian..我的应用程序是英文的,当我将其更改为 SR 时,它应该是塞尔维亚语..

Thank you.谢谢你。

You should handle locale change in event like onKernelRequest and pass locale to session (if needed - you can prepare your routes to handle _locale part, router should handle it automatically) and pass it to Request.您应该处理诸如 onKernelRequest 之类的事件中的区域设置更改并将区域设置传递给会话(如果需要 - 您可以准备您的路由来处理 _locale 部分,路由器应该自动处理它)并将其传递给请求。 Every text written in app should be translated of course with {{ "lorem ispum"|trans }}.应用程序中编写的每个文本都应该使用 {{ "lorem ispum"|trans }} 进行翻译。 Good luck!祝你好运!

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

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