Class: YamlTranslator::Adapters::GoogleTranslateAdapter

Inherits:
BaseAdapter
  • Object
show all
Defined in:
lib/yaml-translator/adapters/google_translate_adapter.rb

Instance Attribute Summary

Attributes inherited from BaseAdapter

#name

Instance Method Summary collapse

Methods inherited from BaseAdapter

#default_options, #initialize

Constructor Details

This class inherits a constructor from YamlTranslator::Adapters::BaseAdapter

Instance Method Details

#translate(values, options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/yaml-translator/adapters/google_translate_adapter.rb', line 6

def translate(values, options={})
  keys = []
  texts = []
  opts = default_options.merge(options)

  values.each_with_index do |(key, text)|
    keys << key # 0: a.b, 1: a.b.c
    texts << text # 0: a, 1: b
  end
  translated_texts = EasyTranslate.translate(texts, :to => opts[:to], :key => @options[:api_key])
  Hash[keys.zip(translated_texts)]
end