Class: Translatomatic::Provider::Yandex
- Defined in:
- lib/translatomatic/provider/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 provider instance.
-
#languages ⇒ Array<String>
A list of languages supported by this provider.
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( = {}) super() @api_key = [:yandex_api_key] || ENV['YANDEX_API_KEY'] raise t('provider.yandex.key_required') if @api_key.nil? end |
Instance Method Details
#languages ⇒ Array<String>
Returns 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 |