翻譯 symfony2 路由錯誤 (translation symfony2 routing error)


問題描述

翻譯 symfony2 路由錯誤 (translation symfony2 routing error)

The error if access a /login is:

  

No route found for "GET /login"

when I try to access /en/login redirects me to login but I get the same error.

In my routing.yml I have:

<pre class="lang‑yml prettyprint‑override">login:     pattern:   /{_locale}/login     defaults:  { _controller: miomioBundle:Security:login}     requirements:         _locale: es|en|de     options:       expose: true </pre>

‑‑‑‑‑

參考解法

方法 1:

This sounds like you have two separate issues.

  1. The route /login does not exist. You have setup three routes above /es/login, /en/login and /de/login but not /login on it's own.

  2. You must have some access controls setup that do not allow the three routes above to be access be unauthenticated users, hence you are being redirected to /login to authenticate... but as mentioned in point 1 that route does not exist.

To solve point 1 you actually need to setup a route which handles the form for login. See the Symfony docs for step by step approach: http://symfony.com/doc/current/book/security.html#using‑a‑traditional‑login‑form

For point 2 you will need to setup some access controls in your security.yml file to allow users to access your login pages without being logged in:

access_control:
  ‑ { path: ^/es/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  ‑ { path: ^/en/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
  ‑ { path: ^/de/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }

You must already have an access control like the below otherwise your login page would crash in an infinite loop:

access_control:
      ‑ { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }

I have to say though, if it just a simple login form then you would be much better served by sticking with 1 login form and handling the labels and login text with translations instead. http://symfony.com/doc/master/book/translation.html

方法 2:

Take a look at the JMSTranslation Bundle and something that may be of more interest for you the JMSI18nRoutingBundle. The JMSI18nRoutingBundle allows you to specify how your routing will work within your config.yml file.

If you want your URL to be /login using the default locale you'll set something like this up:

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

However if you want your url to always contain a locale, for example: en/login or de/login you'll want to change the stratagy parameter to 'prefix'

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

(by faisbuMarkcdnicoll)

參考文件

  1. translation symfony2 routing error (CC BY‑SA 3.0/4.0)

#internationalization #symfony #routing






相關問題

志願者翻譯對 Delphi 2009 應用程序進行本地化的過程? (Process for localization of Delphi 2009 app by volunteer translators?)

Netbeans 菜單和 i18n (Netbeans menu and i18n)

Menggunakan Perpustakaan Penutupan pada aplikasi Phonegap (Android) (Using Closure Library on Phonegap(Android) application)

支持 SDK 但不支持 PhoneGap 的印度語語言 (Indic Language Support for SDK but not PhoneGap)

翻譯 symfony2 路由錯誤 (translation symfony2 routing error)

Django 沒有正確翻譯網站 (Django not translating the site properly)

django模型翻譯404 (django modeltranslation 404)

您是否知道用於編輯/翻譯資源(.rc)文件的好的程序? (Do you know of a good program for editing/translating resource (.rc) files?)

Struts 2 動作調用丟失 xwork i18n 語言設置 (Struts 2 action call loses the xwork i18n language setting)

移動應用測試 (Mobile application testing)

nuxt-i18n 的延遲加載語言環境 (Lazy load locales for nuxt-i18n)

你能在 next.config 中獲取數據嗎 (Can you fetch data in next.config)







留言討論