tags:

views:

62

answers:

2

Hi,

Thanks in advance,

I am new to Magento and I need help switching languages for users. When a customer visits my website it should use their IP to determine their country and switch the language appropriately.

For example, if I am visiting from France my site should display in French. If any others try from any country the website should be in that country's local language..

-Jeet

A: 

Here's a well-written walkthrough, assuming you're using a separate store view for each language:

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

BenV
+1  A: 

I've done that once for a client. Here is what I have done.

Pre-required : GeoIp library for PHP.

1- Create store views relative to the languages in your Magento admin.

2- Add a filtering system by doing :

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

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

2b - Create a template/page/html/country-filter.phtml in your main/parent theme and put this code which can be changed based 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.*/
 }
}
vrnet
Thanks buddy its really helpful....
Jitendra