linuxfreakphp Posted January 11, 2014 Share Posted January 11, 2014 i know i can just redirect it with jquery ,js - client side, or using php - server side, but what is the fastest way to do that when the page is loading? let say i have users from the us, uk, canada - English language, French, German, Chinese... now where is the best place to detect the ip of the country and then give the user the interface in his language? second question, if the user want to change the language with a language buttons like: English, French, German, Chinese... what is the fastest way to do that again without redirect the page to another page? client side, server side or both. i can track the ip, i can redirect the page in more than one way, but i'm looking for the fastest way and that why I'm asking this. Quote Link to comment Share on other sites More sharing options...
kicken Posted January 11, 2014 Share Posted January 11, 2014 now where is the best place to detect the ip of the country and then give the user the interface in his language?The first place you look should be in the Accept-language header (available via $_SERVER['HTTP_ACCEPT_LANGUAGE']) the browser sends. That will tell you which languages the user wants and in what preference order. For example my browser sends: Accept-language: en-US,en;q=0.8,de;q=0.6Which means my ideal language is en-US (American English), my second-choice would be en (Generic English), and lastly de (German). If by chance the client does not send such a header, then you can either fall-back to some kind of IP detection (just google for services) or pick a default language. As for changing the language if the user decides they want something else, the simplest thing is to just reload the page. Any other method would get fairly involved with JS and having to replace text nodes on the page. Just have a link the user clicks which reloads the current page and sets their language preference somewhere (session/cookie). Quote Link to comment Share on other sites More sharing options...
linuxfreakphp Posted January 14, 2014 Author Share Posted January 14, 2014 (edited) Thanks kicken, your answer answered my question and after a addition search in Google i build what i wanted and test it on line in my site. in this site case ip tracking is better because many people in county use browsers that show "en" and not the first language of my country and that is why i chose the ip tracking and not $_SERVER['HTTP_ACCEPT_LANGUAGE'. my browser chrome gave: "en-US,en;q=0.8" my browser firefox gave: "en-US,en;q=0.5" my browser opera gave: "en-US,en;q=0.9" Edited January 14, 2014 by linuxfreakphp Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.