检测输入语言
将主要接受两种语言(英语和阿拉伯语)的输入。
检测使用哪种语言的最简单方法是什么?
Will be accepting input mainly in two languages (English & Arabic).
What would be the simplest way to detect which language was used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这个 pear 包可能有帮助,但我没有使用它:
http://pear.php.net/package /Text_LanguageDetect
This pear package may help, but I didn't use it:
http://pear.php.net/package/Text_LanguageDetect
看看这篇文章 Checking browser's language by PHP? 这是我知道的唯一方法。检查浏览器的语言,假设这是用户的主要语言
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
没有办法 100% 可靠地进行测试,但您可以尝试检查浏览器应随请求发送的 Accept-Language 标头,以确定要使用哪种语言。这将包含客户端愿意接受的语言列表,还包括服务器可以用来确定首选语言的质量分数。
不过,请为用户提供手动设置语言的选项,正如我所说,它可能不是 100% 可靠。
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html 提供了有关接受语言标头的更多技术细节。
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.