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.

1 thought on “How do I load web templates based on browser language?”

  1. 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.

    Reply

Leave a Comment