• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Interesting Question :)

yarassa

New Member
Anyone got an program or idea about language redirection on php. ( if not php it is in js. ) What is this: if my operating system language is english the page redirects http://yours.com/english or the language is french the page redirects http://yours.com/french or... i saw this in adexit.com. it is an example. If you help me i will pleased to you because i really need it for a good user friendly page. Thanks...
 
There's two (actually three) ways to do this. If you want to use server side scripting look for the HTTP_ACCEPT_LANGUAGE header which is two letters followed by a hyphen followed by two more letters to make language-country.
So the US would be en-us, while in the uk it would be en-uk and for Australia en-au. This allows you to select on language or on region or both.
If you use a client side scripting language there's a browserLanguage property in the navigator object you can check for that contains the same information (for IE anyway, no idea about Netscape).
For a list of language/country combinations: http://msdn.microsoft.com/workshop/author/dhtml/reference/language_codes.asp

The last method would be to determine it using the visitor's IP.

I'd suggest using the http header, it's the easiest way. Although I'd also suggest to provide visitors with a clear and easy way to change the language you show a site in.
Just because someone has one language indicated doesn't mean they'll actually be able to understand it. Most people don't know it's there and that they can change it.
 
Originally posted by CareBear
There's two (actually three) ways to do this. If you want to use server side scripting look for the HTTP_ACCEPT_LANGUAGE header which is two letters followed by a hyphen followed by two more letters to make language-country.
So the US would be en-us, while in the uk it would be en-uk and for Australia en-au. This allows you to select on language or on region or both.
If you use a client side scripting language there's a browserLanguage property in the navigator object you can check for that contains the same information (for IE anyway, no idea about Netscape).
For a list of language/country combinations: http://msdn.microsoft.com/workshop/author/dhtml/reference/language_codes.asp

I dont understand that. My english isnt good for this. Server side scripting -> PHP and Client Side Scripting -> JS . Isnt it??? I remember than. How is french? It is easy redirecting to en* property. And i dont understand that HTTP_ACCEPT_LANGUAGE. It is write enviremental ' en-us, fr, etc... '

Thank you Carebear! You help me too much these times. :)
 
Originally posted by yarassa
I dont understand that. My english isnt good for this. Server side scripting -> PHP and Client Side Scripting -> JS . Isnt it
Yes that's right :)

This should work:
PHP:
$Lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0, 2);
switch ($Lang) {
case "en":
	echo "hello, welcome to the blahblah site";
	break;

case "fr":
	echo "bonjour, bienvenu au site blahblah";
	break;

default:
	echo "unknown or not supported by browser so it's best to default to the language most of your visitors use";
}
 
Thank you carebear. A question too is it for all operating systems or anly for windows? Thank you again...
 
Originally posted by yarassa
Thank you carebear. A question too is it for all operating systems or anly for windows? Thank you again...
Since you use it on the server side it doesn't really matter. As long as you make sure you handle the "default" case as well everyone will still see your site. :)

Every version of IE from 4+ upwards supports HTTP_ACCEPT_LANGUAGE.
I know Netscape does too but I have no idea which versions do and which don't sorry

(Btw-since you're from turkey I'll add that tr is the language code for Turkish :) )
 
Back
Top