Hello,
I have www.cascompany.net website, it build multilanguage, using /es/ directory mapped to es.cascompany.net for spanish, additionally... I also have www.cascompany.com domain, that points to the .net, like both open the same site (parked domain).
Now... I get and modified a little some auto language script (detect browser lang, put a cookie, etc.), also on the site Its a drop down that sets a cookie and change language as well.
Then, WITHOUT the "auto lang" script, basically... say you are in the (english web)
http://www.cascompany.net/hosting-solutions-shared-dedicated/shared-hosting/web-hosting/shared-web-hosting.html
and click on the "Language" to go to the spanish version, is does okey, and redirects you to :
http://es.cascompany.net/soluciones-de-hosting/alojamiento-web-compartido/alojamiento-web/alojamiento-compartido.html
Now, another problem is that I have
https://secure.cascompany.net/ ...with a WHMCS integrated, then was the need to do the auto lang script with cookies, to know in what language the client was, to load the correct english or spanish menues, to accomplish client path to order. (because the contexts were web and es, and each one have its domain, like www.cascompany.net and es.cascompany.net ... but here with the secure site, Its only one, and I need to load proper context anyway....
So I end up with this:
<?php
if($modx->context->get('key') != "mgr"){
/* Setting variables */
$langs = array('en', 'es');
$cookie_name = "cas_lang";
$cookie_domain = ".cascompany.net";
/* Check If provided ?lang=en/es variable */
if (!empty($_GET['lang']) && in_array($_GET['lang'], $langs)) {
$lang = $_GET['lang'];
$set_cookie = true;
} else {
/* Do we have cookie already? */
if ( isset($_COOKIE[$cookie_name]) AND !empty($_COOKIE[$cookie_name]) AND in_array($_COOKIE[$cookie_name], $langs) ) {
/* Si tenemos cookie, leerlo a la variable $lang */
$lang = $_COOKIE[$cookie_name];
} else {
/* De lo contrario, leer el lenguage del browser */
if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
$browserlang = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
$li = 999;
$lang = $langs[0];
foreach ($langs as $l) {
$x = strpos($browserlang, $l);
if ($x !== false && $x<$li) {
$li = $x;
$lang = $l;
}
}
} else {
$lang = $langs[0];
}
/* Set cookie */
$set_cookie = true;
}
}
/* Finally set cookie */
if ($set_cookie) { setcookie("$cookie_name", $lang, time()+(60*60*24*365), "/", $cookie_domain); }
/* Cambiar el context, segun la variable del cookie */
switch ($lang) {
case 'es':
//switch the context
$modx->switchContext('es');
//set the cultureKey
$modx->setOption('cultureKey', 'es');
break;
default:
// Set the default language/context here
$modx->switchContext('web');
$modx->setOption('cultureKey', 'en');
break;
}
/* If mgr end */
}
Now... this cames with another problems.... it works, it detects language, it sets the cookie BUT...
Problem I have is that with this activated.... if you get in the site, and then change language, it dont change domain, it just swich contexts (wich is better to have the same domain, and not subdomains) but... then you end with something like this :
http://www.cascompany.net/soluciones-de-hosting/alojamiento-web-compartido/alojamiento-web/alojamiento-compartido.html
That is... basically... the "main domain", but with the "es" context url... while you´re in the site, it shows okey... but if you save the link (or say, the link goes to search engine this way), and you access it again, it will give you to home page, like if link doesnt exist. WHY? well... just because its loading main context, with a url of another context.
ALSO... with the plugin activated, if I load the ".com" domain, ie www.cascompany.com/someurl.... It gets 503 errors.
like it will show url of the current context... but if youre in the es context (by cookie) and you try to access a page on the english context using the .com domain, it will give a horrible 503 error.
So far... the plugin works, but I need to also check in some way the current url and know what context is this url from, and switch context according.
Any ideas?
Right now I have disabled the plugin on modx, but still working on the WHMCS (as its the only way to switch language correctly) but so far, I dont see problems on the whmcs part of it.
Now... accessing from www.cascompany.com domain to a URL on the "es" context like:
www.cascompany.com/soluciones-de-hosting/alojamiento-web-compartido/alojamiento-web/alojamiento-compartido.html
will take me to the english home page, (main context).
only english urls works okey, like:
www.cascompany.com/hosting-solutions-shared-dedicated/shared-hosting/web-hosting/shared-web-hosting.html
goes okey, like the .net, because its main context url.
Dunno if someone will understand all this, but in case you do... maybe you know how can I fix my plugin, so it also detects the url and what context its from, to correctly show the page, without 404 or 503 errors.
Thanks in advance.