In my Rails 3 application, users may write messages in forum. I would like to identify what the language is for a given message. I'm interested in English, Russian, and Hebrew languages. Is there any built-in library in Ruby/Rails for such a task? If not, any ideas will be appreciated.
8 Answers
Use this: https://github.com/nashby/wtf_lang
"ruby is so awesome!".lang # => "en"
"ruby is so awesome!".full_lang # => "ENGLISH"
1 Comment
Misha Moroshko
Thanks! Do you know if there is something similar that can translate one language to other and uses Google translator ?
You can use the api provided by google to guess it with google translate.
See here for documentation : http://code.google.com/apis/language/translate/v1/using_rest_langdetect.html
4 Comments
Misha Moroshko
There is no "Using Ruby" section there :(
Matt
Oh, in that case you'll have to use Java... Sorry, couldn't resist :). It has a JSON interface. You can generate and parse JSON easily with Ruby.
Hartator
In fact, there are just examples, you have to anyway parse the JSON in every language. In ruby, you can use this : developer.yahoo.com/ruby/ruby-json.html
Henley Wing Chiu
Not the best solution. Google has rate limits. There's a dependency on a 3rd party.. you want to limit those as much as possible.
Take a look at this blog
http://blog.kenweiner.com/2008/04/server-side-language-detection-with.html
This may be helpful
Comments
Language Detection API provides Ruby GEM to detect language.
1 Comment
Misha Moroshko
Looks interesting. Thanks for posting this!
Just a quick demo of WhatLanguage for anyone interested : http://www.youtube.com/watch?v=lNqZ2cqOReo&list=UUJ_3fstMOH-g4yBxtvgAWkw&index=0&feature=plcp