Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/linguo/core_ext/string.rb

Instance Method Summary collapse

Instance Method Details

#langArray

Retrieves all the languages detected for the current string sorted by confidence.

Requires Linguo::Config.api_key or ENV['LINGUO_API_KEY'] to be set up.

Examples:

"simple text".lang # => ["en", "fr"]

Returns:

  • (Array)


11
12
13
14
15
16
# File 'lib/linguo/core_ext/string.rb', line 11

def lang
  l ||= Linguo.detect(self, Linguo::Config.api_key)
  l.detections.map {|x| x['language']}
rescue => e
  raise Linguo::Errors::LinguoError, e.message
end