Helpful Information
 
 
Category: PHP
user's language

Hi, does anybody know how to get the user's language using PHP or JS or something.

I want to redirect the user depending on his language settings.
It's important to get the real settings and not only the browser's version.

Thanks for any ideas help.



bye

Joanna

Why not just let them choose a language? I'm not sure there's a way to grab the language, but there prolly is if there's a browser setting for it.

that can be done in javascript by extractiong a string from the browser name i think.

thanx for your replies!

I'm german, and when I'm visiting www.google.com it puts me to www.google.de -> the german version.
It's not stored in any kind of cookies or something.

I'm sure it's possible to get the user's language and not only the browser's language. I know there's a way with cgi, and now I'm looking for a PHP version.

I think JS only gives you the language of the browser and that's it, but hey... maybe I'm wrong !?!



any ideas?


Joanna

Try using strstr($HTTP_ACCEPT_LANGUAGE,"en-us")

as in


if(strstr($HTTP_ACCEPT_LANGUAGE,"en-us")) {
Header("Location: http://us.domain.ext/");
} else {
Header("Location: http://domain.ext/choose.php]");
}

Thank you for the answers but I'm not sure if this is the way.

I set my Browser's language to spanish then I deleted all cookies and went to www.google.com and voilá I was redirected to the german version.

It seems to me as if google doesn't use

$HTTP_ACCEPT_LANGUAGE

but something more powerful.

Isn't there a way to detect the OS language settings?



Joanna

They are probably just basing it off your IP address. They can know which countries blocks of IPs are from and then assume you want whatever corresponding language they have for your country.

When I was in Japan for a year I had a Japanese based ISP and I would always get redirected to japanese versions of various sites. It got really annoying.










privacy (GDPR)