diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-09-23 23:00:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-23 23:00:12 +0200 |
commit | 0d6b878808a02aa4a544e894f06419c0f612c163 (patch) | |
tree | 119723ea46dd8525c370fee1235c3c9d42e55937 /app/lib/translation_service.rb | |
parent | d2f7e30a283a1dca1f7974884ac0c237b93903ad (diff) |
Add user content translations with configurable backends (#19218)
Diffstat (limited to 'app/lib/translation_service.rb')
-rw-r--r-- | app/lib/translation_service.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/app/lib/translation_service.rb b/app/lib/translation_service.rb new file mode 100644 index 000000000..526e26ae5 --- /dev/null +++ b/app/lib/translation_service.rb @@ -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 |