0

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

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

Cœur
  • 37,241
  • 25
  • 195
  • 267
Ahmad
  • 36
  • 2

3 Answers3

1

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

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

reader_1000
  • 2,473
  • 17
  • 15
0

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

Community
  • 1
  • 1
Xavjer
  • 8,838
  • 2
  • 22
  • 42
0

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.

GordonM
  • 31,179
  • 15
  • 87
  • 129
  • This doesn't look like it will give me some sort of feedback on what language was used for the input, does it? – Ahmad Oct 03 '11 at 07:11
  • In that case, short of manual checking, it can't be done. The only real clue as to what language the client is using is the accept-language header. In theory you could check the byte sequences in the input to determine what character set the input is in (assuming it's a unicode string or other multibyte encoding) but that's far from reliable, and even then it isn't precise enough. Just because the input is using Latin characters doesn't mean it's English. It could be French or German or any of a number of Latin languages. – GordonM Oct 03 '11 at 07:38