我在Symfony3應用上實施翻譯。我讀了the book並在我的路線開始時實施了_locale
var。我還設置了從/
到/en
的重定向,並定義了翻譯器回退。在FOSUserBundle路由中未使用Symfony3本地語言
這是作爲打算,除了FOSUserBundle路線。由於它們沒有在我自己的路由中定義,因此它們不會處理{_locale},並且在我訪問它們時重置爲默認語言。 (/de/mypage
=>/profile
=>/en/mypage
)
我的翻譯文件存儲在app/ressources/translations
,和我所有的翻譯完成樹枝的一面。
app_localized:
resource: "@AppBundle/Controller/"
type: annotation
prefix: /{_locale}
app:
path:/
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /en
permanent: true
我在書中也被建議設置在控制器中的翻譯所看到的,但對我來說,我得到了一些,也不要認爲這是有價值的在他們每個人的語言檢查重複。
我也想過在會話中存儲_locale
var,並放置了一個globale監聽器,但似乎有點太多了,所以我想我可能會丟失一些東西。
那麼,如何通過URL處理全局語言,包括FOSUserBundle路由,而不需要在每個控制器中重複代碼?
其實,我的FOSRout就是這樣。 fos_js_routing: 資源: 「@ FOSJsRoutingBundle /資源/配置/路由/ routing.xml」
fos_user_security:
resource: "@FOSUserBundle/Resources/config/routing/security.xml"
prefix: /{_locale}
requirements:
_locale: '%app_locales%'
fos_user_profile:
resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /{_locale}/profile
requirements:
_locale: '%app_locales%'
fos_user_register:
resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /{_locale}/register
requirements:
_locale: '%app_locales%'
fos_user_resetting:
resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /{_locale}/resetting
requirements:
_locale: '%app_locales%'
fos_user_change_password:
resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /{_locale}/profile
requirements:
_locale: '%app_locales%'
是的我實現了fallback和default_locale參數。關於路線,我嘗試過,但我仍然遇到問題。當我嘗試更改當前語言時同樣適用 –
是否可以使用FOSUser路由查看所有routing.yml文件? –
當然,我會編輯我的第一篇文章 –