module Lit::CloudTranslation

Public Instance Methods

configure(&block) click to toggle source

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

@example

Lit::CloudTranslation.configure do |config|
  # For Yandex, this overrides the YANDEX_TRANSLATE_API_KEY env
  config.api_key = 'my_awesome_api_key'
end
# 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
provider() click to toggle source

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

# File lib/lit/cloud_translation.rb, line 18
def provider
  @provider
end
provider=(provider) click to toggle source

Sets the provider for cloud translations. @param [Class] provider Selected translation provider,

descending from Lit::CloudTranslation::Providers::Base
# File lib/lit/cloud_translation.rb, line 12
def provider=(provider)
  @provider = provider
end
translate(text:, from: nil, to:, **opts) click to toggle source

Uses the active translation provider to translate a text or array of texts. @param [String, Array] text The text (or array of texts) to translate @param [Symbol, String] from The language to translate from. If not given,

auto-detection will be attempted.

@param [Symbol, String] to The language to translate to. @param [Hash] opts Additional, provider-specific optional parameters.

# 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