I'm implementing translation on my Symfony3 app. I read the book and implemented the _locale
var at the beginning of my route. I've also set a redirection from /
to /en
, and define the translator fallbacks.
This is working as intend, except for FOSUserBundle route. Since they aren't define on my own routing, they don't take care of the {_locale}, and they reset to the default language when I visit them. (/de/mypage
=> /profile
=> /en/mypage
)
My translation files are stored in app/ressources/translations
, and all my translation are done twig side.
app_localized:
resource: "@AppBundle/Controller/"
type: annotation
prefix: /{_locale}
app:
path: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /en
permanent: true
I saw in the book it was advised to set the translation in controller, but in my case, I got some, and don't think it's valuable to repeat in each of them the language check.
I have also thinking of store the _locale
var in session, and put a globale listener, but seems a bit too much, so i think i am probably missing something.
So, how to handle globale language throught URL, including on FOSUserBundle route, without repeat code in each controller?
Actually, my FOSRout are like that. fos_js_routing: resource: "@FOSJsRoutingBundle/Resources/config/routing/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%'