Add user content translations with configurable backends (#19218)
This commit is contained in:
parent
d2f7e30a28
commit
0d6b878808
16 changed files with 306 additions and 11 deletions
23
app/lib/translation_service.rb
Normal file
23
app/lib/translation_service.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
# 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
|
Loading…
Add table
Add a link
Reference in a new issue