Class: GTranslate::Translator

Inherits:
Object
  • Object
show all
Defined in:
lib/g_translate/translator.rb

Instance Method Summary collapse

Constructor Details

#initialize(text, source, target) ⇒ Translator

Create an instance with the specified options

Parameters

text<String>

The text you want to be translated

source<String>

The source of the language. Currently only iso_639_2 codes are allowed (2 letter codes i.e. English -> en, German -> de, etc)

target<String>

The target of the language. Same as source, only iso_639_2

Returns

GTranslate:: a GTranslate object



21
22
23
24
25
26
# File 'lib/g_translate/translator.rb', line 21

def initialize( text, source, target )
  assert_valid_text! text
  assert_valid_iso_639_2! source, target
  
  @text, @source, @target = text, source, target
end

Instance Method Details

#translateObject

Do the actual translation.

Returns
String:: the translated text



34
35
36
# File 'lib/g_translate/translator.rb', line 34

def translate
  client.request :text => @text, :source => @source, :target => @target
end