|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Feb 2006
Location: Hamburg, Germany
Posts: 526
|
Hi,
I have a website in two languages, English and German: www.website.com/en/ www.website.com/de/ How can I make sure that each visitor is sent to the correct language version? I've been doing quite a bit of searching but can't decide between a javascript or php based solution. I need a script that detects the user's browser language and then immediately renders the website in his/her language. However, the user should also be given the opportunity to switch to the other language should s/he wish to. Any ideas on how to implement this? |
|
|
|
|
|
#2 |
|
Google search user
![]() Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 9,127
|
language
When a browser makes an HTTP request it sends headers. You could try using
$_SERVER["HTTP_ACCEPT_LANGUAGE"] and $_SERVER["HTTP_ACCEPT_CHARSET"]) |
|
|
|
|
|
#3 |
|
Community Advisor
![]() ![]() Join Date: May 2003
Location: Washington, DC
Posts: 9,134
|
Honestly, the best way is to:
1) pick a language which the majority of your users use and make this the default 2) put a clear indication of how to switch languages in the site navigation Trying to auto-detect can get very annoying for people who are, say, visiting a foreign country and keep getting served pages in arabic they can't even begin to comprehend. |
|
|
|
|
|
#4 |
|
SitePoint Evangelist
![]() ![]() ![]() ![]() Join Date: Feb 2006
Location: Hamburg, Germany
Posts: 526
|
Hi wwb_99,
You are right of course. On every page there will be a switch language button in the top right corner, so people can easily switch to their preferred language at any time. However, the very first time someone visits my site, it should be served in his/her system language. I think this makes total sense, not least because the chances of getting it right are pretty high actually. So what would be the best way to do it? |
|
|
|
|
|
#5 |
|
SitePoint Mentor
![]() Join Date: Jun 2004
Location: Copenhagen, Denmark
Posts: 5,819
|
As Mittineague said, the HTTP-request may contain a header "Accept-Language", which specifies a list of languages, in order of preference. Set a cookie, when you have decided, so that the next time the user comes back, you use the cookie instead. That way, people have to switch language once.
|
|
|
|
|
|
#6 | |
|
SitePoint Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2004
Location: Åsnorrbodarna
Posts: 11,581
|
Quote:
A sample header can look like this, Code:
Accept-Language: en-GB, sv;q=0.7, en;q=0.9
|
|
|
|
|
|
|
#7 |
|
SitePoint Enthusiast
![]() Join Date: May 2007
Posts: 25
|
I've implemented this in the following way:
1) Detect the BrowserLanguages 2) Check that this Languages exists in your system 3a) Set this Language to the user session 3b) Set a Language via URL (forced) 4) Include the translated file Source: http://svn.gna.org/viewcvs/clansuite...49&view=markup Feedback appreciated. Regards, v |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 18:28.













Linear Mode
