Changelanguage across sub-domains
Hi All,
I would like to be able to use the excellent change language extension across subdomains,
i.e. fr.brainboxes.com, http://www.brainboxes.com, de.brainboxes.com
www. -> english, is the language fallback
fr -> french
de -> german
I have made some small modifications to the change language code in order to enable this, while keeping the original functionality the same.
In brief, this function added to tl_page.php and ModuleChangeLanguage.php:
Code:
private function checkForSubDomain($domain)
{
//remove subdomain, for case where languages hosted on separate sub domains e.g. fr.domain.com vs www.domain.com || domain.com
if(substr_count($domain, '.') > 1)
{
$domain = substr($domain, strpos($domain, '.') +1 );
}
return $domain;
}
and in 3 places in the code where sql shows: 'WHERE dns= ?' change to 'WHERE dns LIKE ?'
where the question mark is substituted with
Code:
'%' . $this->checkForSubDomain( $objPage->domain )
However I still have one problem.
The default page of the non-english subdomains are not correctly found:
fr.brainboxes.com -> goes to page not found
this is due to a function in Frontend.php line 123: getRootIdFromUrl
Code:
protected function getRootIdFromUrl()
{
$host = $this->Environment->host;
$accept_language = $this->Environment->httpAcceptLanguage;
$time = time();
// Find the matching root pages (thanks to Andreas Schempp)
$objRootPage = $this->Database->prepare("SELECT id, dns, language, fallback FROM tl_page WHERE type='root' AND (dns=? OR dns=? OR dns='')" . ((count($accept_language) > 0) ? " AND (language IN('". implode("','", $accept_language) ."') OR fallback=1)" : " AND fallback=1") . (!BE_USER_LOGGED_IN ? " AND (start='' OR start<$time) AND (stop='' OR stop>$time) AND published=1" : "") . " ORDER BY dns DESC" . ((count($accept_language) > 0) ? ", language='". implode("' DESC, language='", $accept_language) ."' DESC" : ""))
->limit(1)
->execute($host, 'www.'.$host);
return $objRootPage->numRows ? $objRootPage->id : 0;
}
Now I have no fallback language on the subdomain no page is found, if I go to that page with a webbrowser which doesnt report support for the language through httpAcceptLanguage
Not sure what the best way to deal with this is?
Am I using contao in an unusual way?
Andreas since you wrote both the extension and the SQL, what would you advise?
Re: Changelanguage across sub-domains
You don't need to modify the extension! Switching between multiple (sub)domains is supported. What you need to consider is, you must have one fallback language for EVERY subdomain, because to Contao, they are unique domains. After you enabled all fallback checkboxes, you should have the option to link the domains.
Re: Changelanguage across sub-domains
thanks for the quick reply, you may yet save me from wasting my time ;o)
I hadn't updated the extension since: 0.6.3
I updated and everything works!
THANKS!!!