12

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.

1

8 Answers 8

7

Use this: https://github.com/nashby/wtf_lang

"ruby is so awesome!".lang # => "en"
"ruby is so awesome!".full_lang # => "ENGLISH"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Do you know if there is something similar that can translate one language to other and uses Google translator ?
5

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

There is no "Using Ruby" section there :(
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.
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
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.
2

Since you're concerned with languages with different character sets you could dig up the character codes that are predominantly in your strings. You could then see if they fall into the code sets that represent hebrew / cryllic characters.

Comments

2

Perhaps you could look at the whatlanguage gem?

Comments

1

Take a look at this blog
http://blog.kenweiner.com/2008/04/server-side-language-detection-with.html
This may be helpful

Comments

1

Language Detection API provides Ruby GEM to detect language.

1 Comment

Looks interesting. Thanks for posting this!
0

Just a quick demo of WhatLanguage for anyone interested : http://www.youtube.com/watch?v=lNqZ2cqOReo&list=UUJ_3fstMOH-g4yBxtvgAWkw&index=0&feature=plcp

Comments

0

http://rubygems.org/gems/prose Prose dose it without a gem. Try it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.