开发者

Detecting input language [duplicate]

开发者 https://www.devze.com 2023-04-10 09:33 出处:网络
This question already has answers here: Detect language from string in PHP (19 answers) 开发者_开发百科
This question already has answers here: Detect language from string in PHP (19 answers) 开发者_开发百科 PHP: How do I detect if an input string is Arabic (10 answers) Closed 9 years ago.

Will be accepting input mainly in two languages (English & Arabic).

What would be the simplest way to detect which language was used?


This pear package may help, but I didn't use it:

http://pear.php.net/package/Text_LanguageDetect


Look at this post Checking browser's language by PHP? this is the only way I know of. to check the language of the browser, assuming this is the user's main language


There's no way to test 100% reliably, but you can try checking the Accept-Language header that the browser should send with its requests to determine which language to use. This will contain a list of languages the client is willing to accept, it also includes a quality score that the server can use to determine the preferred language.

Do provide the option for the user to manually set the language as well though, as I said it might not be 100% reliable.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html gives more technical details on the accept-language header.

0

精彩评论

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