class YamlTranslator::Adapters::GoogleTranslateAdapter
Public Instance Methods
translate(values, options = {})
click to toggle source
Translate for locale texts @param [Hash] locale texts of translate target @return [Hash] locale texts
# File lib/yaml-translator/adapters/google_translate_adapter.rb, line 9 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