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.

Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746
  • 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 Answers8

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
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
  • There is no "Using Ruby" section there :( – Misha Moroshko May 05 '11 at 13:01
  • 2
    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. – 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
  • 2
    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. – 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
2

Perhaps you could look at the whatlanguage gem?

Caley Woods
  • 4,707
  • 4
  • 29
  • 38
1

Language Detection API provides Ruby GEM to detect language.

Laurynas
  • 3,829
  • 2
  • 32
  • 22
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
0

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