Switch Languages ​​in Magento

Thanks in advance,

I am new to Magento and I need help switching languages ​​for users. When a client visits my site, he must use his IP address to determine his country and switch the language accordingly.

For example, if I visit France, my site should appear in French. If anyone else tries from any country, the website should be in that country in the local language.

-Jeet

+4
source share
2 answers

I did this once for a client. Here is what I did.

Preliminary: GeoIp library for PHP.

1- Create repository views regarding languages ​​in your Magento administrator.

2- Add a filtration system by doing:

2a - edit the page.xml layout file of the main / parent theme and around line 35/36 (add in the handle:

<block type="page/html" name="country-filter" output="toHtml" template="page/html/country-filter.phtml" /> 

2b - Create the template / page / html / country -filter.phtml in the main / parent theme and put this code, which can be changed depending on your needs:

 if(!isset($_COOKIE['frontend'])) { setcookie("frontend",session_id(),time()+60*60*24,"/",""); $ip = $_SERVER['REMOTE_ADDR']; $country = geoip_country_name_by_name($ip); switch($country) { case 'France': $url = $this->getUrl() . '?___store=YOUR_STORE_VIEW_CODE_FOR_FRANCE'; header( 'Location:' . $url) ; /* (Maybe add "exit;" here)*/ break; // (etc... for other cases) default: break; /* No need to specify a country/store view for default as you must have done that in System > Manage Stores in your Magento backend.*/ } } 
+1
source

Here's a well-written walkthrough that assumes you are using a separate repository for each language:

http://fooit.blogspot.com/2009/08/auto-redirect-by-language-for-magento.html

0
source

All Articles