-1

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.

gkennedy87
  • 52
  • 8
  • How you are using the templates. Can you show some code for setting the templates and selecting the language. After viewing them I can suggest you some condition or logic to resolve your query. – John Doe Feb 16 '21 at 03:53
  • https://stackoverflow.com/questions/1043339/javascript-for-detecting-browser-language-preference – Wils Feb 16 '21 at 03:59

1 Answers1

0

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.

  • Thanks. I think I will use this to determine the default view, and then use the language switcher to allow users to change their language preferences manually. – gkennedy87 Feb 16 '21 at 12:25