Class: Translate

Inherits:
Cogibara::OperatorBase show all
Defined in:
lib/cogibara/operators/translate.rb

Constant Summary collapse

LANGUAGES =
{'english' => 'en-US', 'English' => 'en-US', 'Japanese' => 'ja', 'japanese' => 'ja', 'en-US' => 'en-US', 'dutch' => 'nl-NL', 'Dutch' => 'nl-NL', 'German' => 'de-DE','german' => 'de-DE', 'Spanish' => 'es-US', 'spanish' => 'es-US'}

Instance Attribute Summary

Attributes inherited from Cogibara::OperatorBase

#clientID, #message_structure, #message_text, #operator_config

Instance Method Summary collapse

Methods inherited from Cogibara::OperatorBase

#confirm, #initialize, #receive_message, #say

Constructor Details

This class inherits a constructor from Cogibara::OperatorBase

Instance Method Details

#initialize_operatorObject



7
8
9
# File 'lib/cogibara/operators/translate.rb', line 7

def initialize_operator
  @bing = BingTranslator.new('wstrinz', 'aMAR9BHp6NxCml97/OjCaZDB/WRpCDCdmXNHXbCz83s=')
end

#process(input) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cogibara/operators/translate.rb', line 16

def process(input)
  message = input.text
  if LANGUAGES.has_key? message
    @language = LANGUAGES[message]
    "Translating from #{message} (#{@language})"
  elsif message =~ /\Aset language/
    @language = LANGUAGES[message.split[2]]
    "Translating from #{message.split[2]} (#{@language})"
  else
    "you said: " + translate(message)
  end
end

#process_file(file) ⇒ Object



29
30
31
32
# File 'lib/cogibara/operators/translate.rb', line 29

def process_file(file)
  message = Cogibara::Transcriber.new.transcribe_lang(file, @language)
  "you said: " + translate(message)
end

#translate(message) ⇒ Object



11
12
13
14
# File 'lib/cogibara/operators/translate.rb', line 11

def translate(message)
  in_language = @bing.detect message
  @bing.translate message, :from => in_language, :to => "en"
end