简体   繁体   中英

How do I load web templates based on browser language?

I'm building a site that will feature a choice of language between English, Japanese, and Korean. The site will be human translated, not machine translated.

I'd like the template to default to the browsers language. For example, if Japanese, the Japanese version will be loaded.

What's the best way to do this? Or how do I ask this question in a way that I can search and find the resources?

Site is built with HTML/CSS/JS and PHP.

You can get user IP from PHP using this:

echo $_SERVER['REMOTE_ADDR'];

and get user location based on IP using this API:

http://www.geoplugin.net/json.gp?ip=*USER_IP_ADDRESS *

a function that get user info from IP can be found here:

Getting visitors country from their IP

but I recommend not to call this API on every page, call it once and save user language somewhere like in the cookie and check the cookie on every page, be careful that user may use a Proxy or VPN, so let the user change the language every time he/she wants.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM