Class: YamlTranslator::Adapters::GoogleTranslateAdapter
- Inherits:
-
BaseAdapter
- Object
- BaseAdapter
- YamlTranslator::Adapters::GoogleTranslateAdapter
- Defined in:
- lib/yaml-translator/adapters/google_translate_adapter.rb
Instance Method Summary collapse
-
#initialize(api_key = nil) ⇒ GoogleTranslateAdapter
constructor
A new instance of GoogleTranslateAdapter.
- #translate(values, options = {}) ⇒ Object
Methods inherited from BaseAdapter
Constructor Details
#initialize(api_key = nil) ⇒ GoogleTranslateAdapter
6 7 8 |
# File 'lib/yaml-translator/adapters/google_translate_adapter.rb', line 6 def initialize(api_key=nil) @api_key = api_key end |
Instance Method Details
#translate(values, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/yaml-translator/adapters/google_translate_adapter.rb', line 9 def translate(values, ={}) keys = [] texts = [] opts = .merge() 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 => @api_key) Hash[keys.zip(translated_texts)] end |