Module: EasyTranslate::Detection
- Included in:
- EasyTranslate
- Defined in:
- lib/easy_translate/detection.rb
Defined Under Namespace
Classes: DetectionRequest
Instance Method Summary collapse
-
#detect(texts, options = nil, http_options = {}) ⇒ String, Array
Detect language.
Instance Method Details
#detect(texts, options = nil, http_options = {}) ⇒ String, Array
Detect language
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/easy_translate/detection.rb', line 12 def detect(texts, = nil, ={}) request = DetectionRequest.new(texts, , ) # Turn the response into an array of detections raw = request.perform_raw detections = JSON.parse(raw)['data']['detections'].map do |res| res.empty? ? nil : res.first['language'] end # And then return, if they only asked for one, only give one back request.multi? ? detections : detections.first end |