class Lit::CloudTranslation::Providers::Base
Abstract base class for cloud translation providers, providing a skeleton for the provider's functionality (mainly the translate
method) as well as a configuration management mechanism.
Attributes
Private Class Methods
# File lib/lit/cloud_translation/providers/base.rb, line 61 def config @config ||= OpenStruct.new end
# File lib/lit/cloud_translation/providers/base.rb, line 51 def configure yield config if block_given? end
# File lib/lit/cloud_translation/providers/base.rb, line 57 def instance @instance ||= new(config) end
# File lib/lit/cloud_translation/providers/base.rb, line 10 def initialize(config) default_config.each do |key, value| config[key] ||= value end @config = config end
Using the provider object's singleton instance, translates a given text from a given language to a different one. @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/providers/base.rb, line 47 def translate(text:, from: nil, to:, **opts) instance.translate(text: text, from: from, to: to, **opts) end
Public Instance Methods
Translates a given text from a given language to a different one. @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/providers/base.rb, line 23 def translate(text:, from: nil, to:, **opts) # rubocop:disable Lint/UnusedMethodArgument, Metrics/LineLength raise NotImplementedError end
Private Instance Methods
Loads specific information from environment variables or other sources as the default configuartion for the translation provider.
This can be overridden using `Lit::CloudTranslation.configure`.
# File lib/lit/cloud_translation/providers/base.rb, line 33 def default_config {} end