<small id='UUSVG'></small><noframes id='UUSVG'>

  • <tfoot id='UUSVG'></tfoot>
    <i id='UUSVG'><tr id='UUSVG'><dt id='UUSVG'><q id='UUSVG'><span id='UUSVG'><b id='UUSVG'><form id='UUSVG'><ins id='UUSVG'></ins><ul id='UUSVG'></ul><sub id='UUSVG'></sub></form><legend id='UUSVG'></legend><bdo id='UUSVG'><pre id='UUSVG'><center id='UUSVG'></center></pre></bdo></b><th id='UUSVG'></th></span></q></dt></tr></i><div id='UUSVG'><tfoot id='UUSVG'></tfoot><dl id='UUSVG'><fieldset id='UUSVG'></fieldset></dl></div>
  • <legend id='UUSVG'><style id='UUSVG'><dir id='UUSVG'><q id='UUSVG'></q></dir></style></legend>

          <bdo id='UUSVG'></bdo><ul id='UUSVG'></ul>

        Symfony2 在路由中使用默认语言环境(一种语言的一个 URL)

        Symfony2 Use default locale in routing (one URL for one language)(Symfony2 在路由中使用默认语言环境(一种语言的一个 URL))
      1. <tfoot id='PG2rk'></tfoot>

          • <bdo id='PG2rk'></bdo><ul id='PG2rk'></ul>

              <small id='PG2rk'></small><noframes id='PG2rk'>

              • <i id='PG2rk'><tr id='PG2rk'><dt id='PG2rk'><q id='PG2rk'><span id='PG2rk'><b id='PG2rk'><form id='PG2rk'><ins id='PG2rk'></ins><ul id='PG2rk'></ul><sub id='PG2rk'></sub></form><legend id='PG2rk'></legend><bdo id='PG2rk'><pre id='PG2rk'><center id='PG2rk'></center></pre></bdo></b><th id='PG2rk'></th></span></q></dt></tr></i><div id='PG2rk'><tfoot id='PG2rk'></tfoot><dl id='PG2rk'><fieldset id='PG2rk'></fieldset></dl></div>
                1. <legend id='PG2rk'><style id='PG2rk'><dir id='PG2rk'><q id='PG2rk'></q></dir></style></legend>
                    <tbody id='PG2rk'></tbody>
                  本文介绍了Symfony2 在路由中使用默认语言环境(一种语言的一个 URL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在用 Symfony2 开发一个网站,我需要翻译它.使用 Symfony2 提供的工具非常简单.但是我遇到一个问题:

                  I am currently developing a website with Symfony2 and I need to translate it. With tools provided by Symfony2 it’s very easy. But I encounter a problem:

                  我想要一个语言(即一个 URL,一种语言)的特定 URL(带前缀),但使用默认语言.具体来说:

                  I would like to have specific URL (with prefix) to a language (ie, one URL, a single language), but with a default language. Concretely:

                  假设默认语言是英文,所以

                  Assume that the default language is English, so

                  • http://example.com/fr/hello 以法语显示页面
                  • http://example.com/it/hello 以意大利语显示页面
                  • http://example.com/en/hello 重定向到 http://example.com/hello(因为 en 是默认语言)
                  • http://example.com/hello 当然页面显示为英文(默认语言)
                  • http://example.com/fr/hello display the page in French
                  • http://example.com/it/hello display the page in Italian
                  • http://example.com/en/hello redirect to http://example.com/hello (because en is the default language)
                  • http://example.com/hello display of course the page in English (default language)

                  我天真地尝试像这样配置我的路由:

                  I naively try to configure my routing like this:

                  #routing.yml
                  _welcome:
                      pattern:  /{_locale}/hello
                      defaults: { _controller: AcmeDemoBundle:Welcome:hello, _locale: en}
                  

                  但这不起作用(http://example.com/en/hello 只显示英文页面和 http://example.com/hello 返回 404 错误).

                  But that’s don’t work (http://example.com/en/hello just display the page in English and http://example.com/hello return 404 error).

                  当然,每次创建两条路线也是可以的,但是非常繁琐.所以我正在寻找一个干净的解决方案.

                  It’s possible, of course, to create two routes each time, but it is very tedious. So I’m looking for a clean solution.

                  顺便说一句,我注意到我正在寻找的 URL 行为正是 Symfony2 的官方文档所采用的行为:

                  Incidentally, I noticed that the behavior I was looking for with URL was exactly the one adopted by the official documentation of Symfony2:

                  http://symfony.com/fr/doc/current/book/translation.html显示法语翻译

                  http://symfony.com/it/doc/current/book/translation.html 显示意大利语翻译

                  http://symfony.com/en/doc/current/book/translation.html 重定向到 http://symfony.com/doc/current/book/translation.html(以英文显示页面)

                  http://symfony.com/en/doc/current/book/translation.html redirect to http://symfony.com/doc/current/book/translation.html (which display the page in English)

                  推荐答案

                  安装JMSI18nBundle并应用策略prefix_except_default.

                  捆绑包将负责为您创建路线.

                  The bundle will take care of creating the routes for you.

                  配置:

                  jms_i18n_routing:
                      default_locale: en
                      locales: [de, en]
                      strategy: prefix_except_default
                  

                  可以在捆绑包的文档中找到更多信息.

                  Further information can be found in the bundle's documentation.

                  这篇关于Symfony2 在路由中使用默认语言环境(一种语言的一个 URL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                    <legend id='gHCCX'><style id='gHCCX'><dir id='gHCCX'><q id='gHCCX'></q></dir></style></legend>
                  1. <i id='gHCCX'><tr id='gHCCX'><dt id='gHCCX'><q id='gHCCX'><span id='gHCCX'><b id='gHCCX'><form id='gHCCX'><ins id='gHCCX'></ins><ul id='gHCCX'></ul><sub id='gHCCX'></sub></form><legend id='gHCCX'></legend><bdo id='gHCCX'><pre id='gHCCX'><center id='gHCCX'></center></pre></bdo></b><th id='gHCCX'></th></span></q></dt></tr></i><div id='gHCCX'><tfoot id='gHCCX'></tfoot><dl id='gHCCX'><fieldset id='gHCCX'></fieldset></dl></div>

                    • <bdo id='gHCCX'></bdo><ul id='gHCCX'></ul>
                      • <tfoot id='gHCCX'></tfoot>

                              <tbody id='gHCCX'></tbody>

                            <small id='gHCCX'></small><noframes id='gHCCX'>