2022-09-23 23:00:12 +02: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
|
2024-10-23 15:32:18 +02:00
|
|
|
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]
|
|
|
|
)
|
2022-09-23 23:00:12 +02:00
|
|
|
else
|
|
|
|
raise NotConfiguredError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-24 18:30:58 +02:00
|
|
|
def self.configured?
|
2024-10-23 15:32:18 +02:00
|
|
|
configuration.deepl[:api_key].present? || configuration.libre_translate[:endpoint].present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.configuration
|
|
|
|
Rails.configuration.x.translation
|
2022-10-24 18:30:58 +02:00
|
|
|
end
|
|
|
|
|
2023-03-16 11:07:24 +01:00
|
|
|
def languages
|
|
|
|
{}
|
2023-03-03 21:06:31 +01:00
|
|
|
end
|
|
|
|
|
2022-09-23 23:00:12 +02:00
|
|
|
def translate(_text, _source_language, _target_language)
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|