how to set language country wise

Author Message

Dhaval Patel

Thursday 17 April 2008 11:45:19 pm

hello,

I have made one site using ez3.10 in two languages english and french.

now i want to make settings such as if any user from france country open the site then the default language must be french and if any user outside from country france then the default language of site must be english.

Is it possible?

Thanks in advance.

With Best Regards,

Dhaval Patel
Team Leader - iNETProcess(I) Pvt. LTD.
[email protected]
Ph No: +91 79 65 12 35 00
http://www.inetprocess.co.in

Łukasz Serwatka

Friday 18 April 2008 12:05:23 am

It is possible. ez.no support language detection for example. Basically you need to detect client language then serve correct siteaccess. There are plenty of examples in the internet how to make it with JavaScript for example.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Dhaval Patel

Friday 18 April 2008 12:16:30 am

thank you for repling.

Is there any setting in ez for this?

and if we do actions as you told then at where we can set the site access and how?

and I have two links on page also. we can also be able to change the language using links also.

With Best Regards,

Dhaval Patel
Team Leader - iNETProcess(I) Pvt. LTD.
[email protected]
Ph No: +91 79 65 12 35 00
http://www.inetprocess.co.in

Łukasz Serwatka

Friday 18 April 2008 12:26:11 am

eZ Publish does not have dedicated setting for it. You have add such functionality (e.g by including the JS code in pagelayout). After eZ Publish installation (with Website Interface package for example) you should have 2 siteaccess if you have choose 2 language

www.example.com/fre
www.example.com/eng

Basically if client locale is set to French then you serve www.example.com/fre if other then www.example.com/eng

Take a look on documentation to learn more about siteaccesses and the multilingual eZ Publish features.

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Dhaval Patel

Sunday 20 April 2008 11:49:41 pm

hello,

i have done this.

i have downloaded ip2country records from here

http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip

I have made one table tbl_ip2country and import all records.

Columns of this table is "id,ip_from,ip_to,country_code2,country_code3,country_name"

now in access.php file, put this line at top.

define( 'DO_AS_PER_LOCALE', 1 );
include_once( 'lib/ezdb/classes/ezdb.php' );

now in function accessType, at line approximately 262,
between if and else if

			else if(DO_AS_PER_LOCALE == true && $_SERVER['REMOTE_ADDR'] != "127.0.0.1")
			{
				// to run this, we have to change db name from settings/site.ini "nextgen" to the current database name
				// and we need ip2country table in that database.
				$remoteIp = $_SERVER['REMOTE_ADDR'];
				//$remoteIp = "121.247.167.243"; for testing => india
				$q = "select * from tbl_ip2country 
					where 
						((SUBSTRING_INDEX( '$remoteIp' , '.', 1 ) * (256*256*256)) + 
						(SUBSTRING_INDEX(SUBSTRING_INDEX( '$remoteIp' , '.', 2 ),'.',-1) * (256*256)) + 
						(SUBSTRING_INDEX(SUBSTRING_INDEX( '$remoteIp' , '.', -2 ),'.',1) * 256 ) + 
						SUBSTRING_INDEX( '$remoteIp' , '.', -1 ))
						between ip_from and ip_to
					";//and lower(country_code2) = 'fr'

				$db = eZDB::instance();

                $result = $db->arrayQuery($q);
				
				if(count($result) > 0 && strtolower($result[0]['country_code2']) == "fr")
				{
					// language is french					
					$access['name'] = "fre";
				}
				else
				{
					$access['name'] = "eng";
					// language is english
				}
				$access['type'] = EZ_ACCESS_TYPE_URI;
			}

and one more thing to do in settings/site.ini file

we have to change this because site.ini file loads after the upper code executes.

User=dbusername
Password=dbpassword
Database=dbname

With Best Regards,

Dhaval Patel
Team Leader - iNETProcess(I) Pvt. LTD.
[email protected]
Ph No: +91 79 65 12 35 00
http://www.inetprocess.co.in

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.