Class: Translatomatic::Translator::Yandex
- Defined in:
- lib/translatomatic/translator/yandex.rb
Overview
Interface to the Yandex translation API
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Yandex
constructor
Create a new Yandex translator instance.
-
#languages ⇒ Array<String>
A list of languages supported by this translator.
Methods inherited from Base
Constructor Details
#initialize(options = {}) ⇒ Yandex
Create a new Yandex translator instance
13 14 15 16 17 |
# File 'lib/translatomatic/translator/yandex.rb', line 13 def initialize( = {}) super() @api_key = [:yandex_api_key] || ENV["YANDEX_API_KEY"] raise t("translator.yandex_key_required") if @api_key.nil? end |
Instance Method Details
#languages ⇒ Array<String>
Returns A list of languages supported by this translator.
20 21 22 23 24 25 26 27 28 |
# File 'lib/translatomatic/translator/yandex.rb', line 20 def languages @languages ||= begin request = Translatomatic::HTTPRequest.new(LANGUAGES_URL) response = request.post(key: @api_key, ui: "en") data = JSON.parse(response.body) || {} langs = data["langs"] || {} langs.keys.flatten.uniq end end |