Jump to content

what is the fastest way to change languages without redirect the page to another page?


linuxfreakphp

Recommended Posts

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.

Link to comment
Share on other sites

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.6
Which 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).

Link to comment
Share on other sites

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 by linuxfreakphp
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.