class Trestle::Mobility::Translators::DeeplTranslator

Public Class Methods

new(*) click to toggle source
# File lib/trestle/mobility/translators/deepl_translator.rb, line 5
def initialize(*)
  begin
    require "deepl"
  rescue LoadError
    raise StandardError, "Add the 'deepl-rb' gem to your Gemfile"
  end

  configure_api_key!
end

Public Instance Methods

translate(text, from, to, query_params = {}) click to toggle source
# File lib/trestle/mobility/translators/deepl_translator.rb, line 15
def translate(text, from, to, query_params = {})
  DeepL.translate(text, from, to, query_params)
end

Private Instance Methods

configure_api_key!() click to toggle source
# File lib/trestle/mobility/translators/deepl_translator.rb, line 20
def configure_api_key!
  DeepL.configure do |config|
    config.auth_key = Trestle.config.mobility.deepl_api_key
  end
end