开发者

Multilanguage webpage: How can i get user language/locale in one easy and reliable step?

开发者 https://www.devze.com 2023-01-30 12:50 出处:网络
I just started developing a multilingual webpage which site users can read and post entries without registration. (It\'s based on Facebook \"like button\" and \"comment social plugin\".)

I just started developing a multilingual webpage which site users can read and post entries without registration. (It's based on Facebook "like button" and "comment social plugin".)

In most case i use Hostip.info to get users language from their ip (based on location) but it's not enought good. In other case i must relies on browsers language (because of unlocated ip开发者_开发百科 address).

I must find a reliable way to decide where my users come from and what language they are speak. I'll be thankful if somebody can help me.

(Temporary i solved the problem with a popup alert box which everybody can set their own locale. In the near future i want just a simple warn that says "You speak english. It's right?")


The request http header should have a "Accept-Language" which you can try and use. I would suggest setting a cookie on the user's preference so that they do not keep getting a different language if they are visiting a foreign country for argument sake.

$_SERVER["HTTP_ACCEPT_LANGUAGE"];
$_SERVER["HTTP_ACCEPT_CHARSET"];
0

精彩评论

暂无评论...
验证码 换一张
取 消