You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mastodon/app/lib/translation_service.rb

42 lines
1.0 KiB
Ruby

# frozen_string_literal: true
class TranslationService
class Error < StandardError; end
class NotConfiguredError < Error; end
class TooManyRequestsError < Error; end
class QuotaExceededError < Error; end
class UnexpectedResponseError < Error; end
def self.configured
if configuration.deepl[:api_key].present?
TranslationService::DeepL.new(
configuration.deepl[:plan],
configuration.deepl[:api_key]
)
elsif configuration.libre_translate[:endpoint].present?
TranslationService::LibreTranslate.new(
configuration.libre_translate[:endpoint],
configuration.libre_translate[:api_key]
)
else
raise NotConfiguredError
end
end
def self.configured?
configuration.deepl[:api_key].present? || configuration.libre_translate[:endpoint].present?
end
def self.configuration
Rails.configuration.x.translation
end
def languages
{}
end
def translate(_text, _source_language, _target_language)
raise NotImplementedError
end
end