Class: Translatomatic::Provider::Yandex

Inherits:
Base
  • Object
show all
Defined in:
lib/translatomatic/provider/yandex.rb

Overview

Interface to the Yandex translation API

Instance Attribute Summary

Attributes inherited from Base

#listener

Instance Method Summary collapse

Methods inherited from Base

#name, supports_alternative_translations?, supports_no_translate_html?, #to_s, #translate

Constructor Details

#initialize(options = {}) ⇒ Yandex

Create a new Yandex provider instance



10
11
12
13
14
# File 'lib/translatomatic/provider/yandex.rb', line 10

def initialize(options = {})
  super(options)
  @api_key = options[:yandex_api_key] || ENV['YANDEX_API_KEY']
  raise t('provider.yandex.key_required') if @api_key.nil?
end

Instance Method Details

#languagesArray<String>

Returns A list of languages supported by this provider.

Returns:

  • (Array<String>)

    A list of languages supported by this provider.



17
18
19
20
21
22
23
24
# File 'lib/translatomatic/provider/yandex.rb', line 17

def languages
  @languages ||= begin
    response = http_client.post(LANGUAGES_URL, key: @api_key, ui: 'en')
    data = JSON.parse(response.body) || {}
    langs = data['langs'] || {}
    langs.keys.flatten.uniq
  end
end