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.
Asked
Active
Viewed 5,269 times
12
-
here good answers too https://stackoverflow.com/questions/3285511/how-can-i-detect-a-users-input-language-using-ruby-without-using-an-online-serv – Oleksandr Bratashov Oct 06 '17 at 09:10
8 Answers
6
Use this: https://github.com/nashby/wtf_lang
"ruby is so awesome!".lang # => "en"
"ruby is so awesome!".full_lang # => "ENGLISH"

Vasiliy Ermolovich
- 24,459
- 5
- 79
- 77
-
Thanks! Do you know if there is something similar that can translate one language to other and uses Google translator ? – Misha Moroshko May 08 '11 at 12:50
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

Hartator
- 5,029
- 4
- 43
- 73
-
-
2Oh, 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. – Matt May 05 '11 at 15:10
-
In fact, there are just examples, you have to anyway parse the JSON in every language. In ruby, you can use this : http://developer.yahoo.com/ruby/ruby-json.html – Hartator May 05 '11 at 15:41
-
2Not the best solution. Google has rate limits. There's a dependency on a 3rd party.. you want to limit those as much as possible. – Henley Oct 27 '13 at 23:42
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.

digitalWestie
- 2,647
- 6
- 28
- 45
1
Take a look at this blog
http://blog.kenweiner.com/2008/04/server-side-language-detection-with.html
This may be helpful

shajin
- 3,214
- 5
- 38
- 53
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

alexizydorczyk
- 850
- 1
- 6
- 25