mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-25 14:05:11 +01:00
24 lines
724 B
Ruby
24 lines
724 B
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 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
|
|
|
|
def translate(_text, _source_language, _target_language)
|
|
raise NotImplementedError
|
|
end
|
|
end
|