You can create an event listener to detect your domain name:
class LocaleListener implements EventSubscriberInterface
{
/**
* Set default locale
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
return;
}
// get domain name
$host = $request->getHttpHost();
// or $host = $request->getHost();
$locale = 'en';
if ($host == 'domain1') {
$locale = 'fr';
}
$request->setLocale($locale);
}
/**
* {@inheritdoc}
*/
static public function getSubscribedEvents()
{
return array(
// must be registered before the default Locale listener
KernelEvents::REQUEST => array(array('onKernelRequest', 17)),
);
}
}
And in your services.yml:
services:
my_locale_listener:
class: MyBundle\LocaleListener
tags:
- { name: kernel.event_subscriber }
You can put in listener constructor default locle from parameters.yml file and if locale is not detected by domain set default locale.