What’s the best way to detect the language of a string?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If the context of your code have internet access, you can try to use the Google API for language detection.
http://code.google.com/apis/ajaxlanguage/documentation/
And, since you are using c#, take a look at this article on how to call the API from c#.
UPDATE:
That c# link is gone, here’s a cached copy of the core of it:
Basically, you need to create a URI and send it to Google that looks like:
This tells the API that you want to translate “hello world” from English to Hebrew, to which Google’s JSON response would look like:
I chose to make a base class that represents a typical Google JSON response:
Then, a Translation object that inherits from this class:
This Translation class has a TranslationResponseData object that looks like this:
Finally, we can make the GoogleTranslator class: