2022-09-24 00:00:12 +03:00
|
|
|
# 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 ENV['DEEPL_API_KEY'].present?
|
|
|
|
TranslationService::DeepL.new(ENV.fetch('DEEPL_PLAN', 'free'), ENV['DEEPL_API_KEY'])
|
|
|
|
elsif ENV['LIBRE_TRANSLATE_ENDPOINT'].present?
|
|
|
|
TranslationService::LibreTranslate.new(ENV['LIBRE_TRANSLATE_ENDPOINT'], ENV['LIBRE_TRANSLATE_API_KEY'])
|
|
|
|
else
|
|
|
|
raise NotConfiguredError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-24 19:30:58 +03:00
|
|
|
def self.configured?
|
|
|
|
ENV['DEEPL_API_KEY'].present? || ENV['LIBRE_TRANSLATE_ENDPOINT'].present?
|
|
|
|
end
|
|
|
|
|
2023-03-16 12:07:24 +02:00
|
|
|
def languages
|
|
|
|
{}
|
2023-03-03 22:06:31 +02:00
|
|
|
end
|
|
|
|
|
2022-09-24 00:00:12 +03:00
|
|
|
def translate(_text, _source_language, _target_language)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|