Welcome Guest, Not a member yet? Register   Sign In
IP tracking help
#1

[eluser]Justin Patel[/eluser]
Hello Friends !!!

I am working on the multiple language. I want to track the IP address and get the name of country and then automatically select the language.

is there any api for that?

which method would be good for this...


Looking forward to here from you
#2

[eluser]xwero[/eluser]
The country doesn't always define the language. For instance in Belgium there are three languages : French, Dutch and German. I think you better get the language string from the browser with the useragent library. It isn't foolproof but i think it's a better method for language detection than using the ip address.
#3

[eluser]Justin Patel[/eluser]
[quote author="xwero" date="1201557006"]The country doesn't always define the language. For instance in Belgium there are three languages : French, Dutch and German. I think you better get the language string from the browser with the useragent library. It isn't foolproof but i think it's a better method for language detection than using the ip address.[/quote]



Great, I just understand 5%.

Please please tell me in m0re details...


thanks
#4

[eluser]xwero[/eluser]
Which 5% did you understand Smile

CIs user agent library gets the string from the browser that gets send along with the http request.
Quote:Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.0.4) Gecko/20060613 Camino/1.0.2
As you can see the language string is embedded (en-US) and with the method accept_lang you can find out if the language you offer exist in the user agent string.
Code:
$langs = array('en','nl','es');
$setlanguage = '';
foreach($langs as $lang)
{
   if($this->agent->accept_lang($lang)){ $setlang = $lang; exit; }
}
if($setlang == '')
{
   // default language
}
else
{
  // set fetched language
}
This is a more correct way than getting the country and selecting the language based on a country because there are more than one country that have different language areas and you don't know if the viewer of your site is indeed from that country or some traveller who connects his own pc in that country, he could have an whole other language than those spoken in the country.




Theme © iAndrew 2016 - Forum software by © MyBB