Jump to content

[SOLVED] Chosing language by domain and not by cookie?


Jikdor

Recommended Posts

Hello Presta forums!

I have 2 domains for my website, one .se for Swedish and a .com domain for English and I would like them to control what language that is used and not load it from a cookie and the flag icons will just point to the different domains. This should be a simple edit but I can not find where is the code the language ID is defined. I was thinking something like:

if ($_SERVER['SERVER_NAME'] == "psybackdrops.com") {
   $id_lang = "1";
}
elseif ($_SERVER['SERVER_NAME'] == "www.psybackdrops.com") {
   $id_lang = "1";
}
elseif ($_SERVER['SERVER_NAME'] == "psybackdrops.se") {
   $id_lang = "4";
} 
elseif ($_SERVER['SERVER_NAME'] == "www.psybackdrops.se") {
   $id_lang = "4";
}



So where in the source code does presta find out what language id to use and how do I edit it to work as I want? I'm thinking it is in smarty.config.inc.php but being a php noob and not slept in days I failed to figure it out and make it work. Help would be very appreciated!!

Link to comment
Share on other sites

You must change it in the cookie. For example:

if ($_SERVER['SERVER_NAME'] == "psybackdrops.com" OR $_SERVER['SERVER_NAME'] == "www.psybackdrops.com") 
   $cookie->id_lang = 1;
elseif ($_SERVER['SERVER_NAME'] == "psybackdrops.se" OR $_SERVER['SERVER_NAME'] == "www.psybackdrops.se") 
   $cookie->id_lang = 4;

Link to comment
Share on other sites

  • 2 weeks later...

It nows does change the language, but does the oposit of what I want. Used English for the se domain and Swedish for the com. Weird. I don't understand at all why its acting this way, makes no sense!

NVM got it working

Edit:

Nope it's not working as I want after all, it sometimes workes, sometimes it don't!

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 8 months later...

yes, but you must change file FrontContoller.php from classes after line 116.

 

Tools::switchLanguage();

 

code:

if ($_SERVER['SERVER_NAME'] == "psybackdrops.com" OR $_SERVER['SERVER_NAME'] == "www.psybackdrops.com")
$cookie->id_lang = 1;
elseif ($_SERVER['SERVER_NAME'] == "psybackdrops.se" OR $_SERVER['SERVER_NAME'] == "www.psybackdrops.se")
$cookie->id_lang = 4;

Link to comment
Share on other sites

yes, but you must change file FrontContoller.php from classes after line 116.

 

Tools::switchLanguage();

 

code:

if ($_SERVER['SERVER_NAME'] == "psybackdrops.com" OR $_SERVER['SERVER_NAME'] == "www.psybackdrops.com")
$cookie->id_lang = 1;
elseif ($_SERVER['SERVER_NAME'] == "psybackdrops.se" OR $_SERVER['SERVER_NAME'] == "www.psybackdrops.se")
$cookie->id_lang = 4;

 

Thanks for this Skurek! Should this code replace the following code?:

 

if (!defined('_USER_ID_LANG_'))
define('_USER_ID_LANG_', (int)$cookie->id_lang);

 

And also, how would I set up the second domain on the registrar site? If one is the prestashop domain, how do I configure the other one?

Link to comment
Share on other sites

  • 1 year later...

I like to switch language initially based on the .TLD of the domain (so .fr .de .co.uk etc) for PS 1.5. I did this in PS 1.3 in the init.php. I think it should now be in frontController like proposed but 1.5 doesn't have switchLanguage() It does have Tools::setCookieLanguage($this->context->cookie); and I tried to switch in the override for Tools class. The code was functioning BUT something before this code is already setting the cookie. And a only want to set the language when no language is selected yet.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...