about summary refs log tree commit diff
path: root/app/lib/translation_service.rb
diff options
context:
space:
mode:
authorClaire <claire.github-309c@sitedethib.com>2022-10-03 09:03:11 +0200
committerGitHub <noreply@github.com>2022-10-03 09:03:11 +0200
commit2aafdd0efb3fa0bf067e0b08a627a462793f296b (patch)
treed559e2dec7ceb4c446db973b5c040a708d1c5756 /app/lib/translation_service.rb
parent9d7c323abdda66423751f3a25faf960674af8a49 (diff)
parent6ee768b7b285382fce3270ad4cf06c71838182d8 (diff)
Merge pull request #1848 from ClearlyClaire/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/lib/translation_service.rb')
-rw-r--r--app/lib/translation_service.rb23
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