Module: Lit::CloudTranslation

Defined in:
lib/lit/cloud_translation.rb

Defined Under Namespace

Modules: Providers Classes: TranslationError

Class Method Summary collapse

Class Method Details

.configure(&block) ⇒ Object

Optional if provider-speciffic environment variables are set correctly. Configures the cloud translation provider with specific settings, overriding those from environment if needed.

Examples:

Lit::CloudTranslation.configure do |config|
  # For Yandex, this overrides the YANDEX_TRANSLATE_API_KEY env
  config.api_key = 'my_awesome_api_key'
end


42
43
44
45
46
47
48
49
50
# File 'lib/lit/cloud_translation.rb', line 42

def configure(&block)
  unless provider
    raise 'Translation provider not selected yet. Use `Lit::CloudTranslation' \
          '.provider = PROVIDER_KLASS` before calling #configure.'
  end
  provider.tap do |p|
    p.configure(&block)
  end
end

.providerObject

Returns the currently active cloud translation provider, descending from Lit::CloudTranslation::Providers::Base.



18
19
20
# File 'lib/lit/cloud_translation.rb', line 18

def provider
  @provider
end

.provider=(provider) ⇒ Object

Sets the provider for cloud translations.



12
13
14
# File 'lib/lit/cloud_translation.rb', line 12

def provider=(provider)
  @provider = provider
end

.translate(text:, from: nil, to:, **opts) ⇒ Object

Uses the active translation provider to translate a text or array of texts.



29
30
31
# File 'lib/lit/cloud_translation.rb', line 29

def translate(text:, from: nil, to:, **opts)
  provider.translate(text: text, from: from, to: to, **opts)
end