i'm making multi language site that can be run from different hosts.
some hosts can only have one language.
i'm having trouble figuring out how to redirect users from one language to another
for example:
if site.com only has de languge (site.com/de)
and someone tries to go directly to site.com/en i want redirect them to site.com/de straight away.
or how to restrict locale prefix based on host(should be dynamic)?
i think there is a way to do that from service listener but i dont know what to pass to it to be able to redirect from it.
First of all I think that this kind of limitations should be provided by httpd server configuration. For me this is a place where you should allow/disallow access based on remote host IP, and then redirect to allowed namespace of the site.
Answering your question try to use JMSI18nRoutingBundle bundle, or similar. In this case you can overload Router/DefaultLocaleResolver.php class, replacing it in configuration (jms_i18n_routing.router.class
).
In your overloaded router add host based resolving to resolveLocale function by checking $request->getClientIp();
. This way not only mainpage will be redirected to "proper" locale but also any link in your application.
I think this is a cleanest way toy implement that.
Good Luck!