0

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

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

2
  • 1
    probably duplication of stackoverflow.com/questions/3541371/… Commented Oct 3, 2011 at 6:52
  • looks like what I was looking for, will check it out. Commented Oct 3, 2011 at 7:14

3 Answers 3

1

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

looks like it'll do. I will test it out.
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

1 Comment

Im looking to test the input. reagdless of the browsrs language. Thanks.
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.

2 Comments

This doesn't look like it will give me some sort of feedback on what language was used for the input, does it?
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.