Jump to content

Language selection based on domain


Recommended Posts

Many of the larger web shops using prestashop have multiple domain focusing on different markets. There are several modules that allow for geolocation based on the customer IP, but when multiple domains are available it is a lot more practical to do translations based on them.

For example, say my shop is called megashop, I have two domains:
megashop.com which is english
megashop.nl which is dutch

I also have two translations files which have both an iso code and a lang_id assigned. So we have the following values:
for the .nl:

iso = nl and lang_id = 5

for the .com:

iso = en and lang_id = 1

Off course if you have more domains, more iso,domain and lang_id combination are possible.

The plan now is, getting the .com domain to switch the language to lang_id =1 and the .nl domain to lang_id = 5.

What we first do is explode the domain to get a value for the TLD (top level domain)

$domainarray = explode('.', $_SERVER['HTTP_HOST']);
$TLD = $domainarray[count($domainarray)-1];

This code returns either com or nl in this example.

Up until this point I could still make everything work. However when trying to make the transition from the domain to the lang_id and iso I ran in to trouble. I tried disabling all language related things from the init.php and commenting out the loading of the lang_id from a cookie, but I just couldn't figure out what to change to make it work uit.

Can anyone help out?

Share this post

Link to post
Share on other sites

  • 2 months later...

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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More