You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
902 B

  1. # frozen_string_literal: true
  2. class TranslationService
  3. class Error < StandardError; end
  4. class NotConfiguredError < Error; end
  5. class TooManyRequestsError < Error; end
  6. class QuotaExceededError < Error; end
  7. class UnexpectedResponseError < Error; end
  8. def self.configured
  9. if ENV['DEEPL_API_KEY'].present?
  10. TranslationService::DeepL.new(ENV.fetch('DEEPL_PLAN', 'free'), ENV['DEEPL_API_KEY'])
  11. elsif ENV['LIBRE_TRANSLATE_ENDPOINT'].present?
  12. TranslationService::LibreTranslate.new(ENV['LIBRE_TRANSLATE_ENDPOINT'], ENV['LIBRE_TRANSLATE_API_KEY'])
  13. else
  14. raise NotConfiguredError
  15. end
  16. end
  17. def self.configured?
  18. ENV['DEEPL_API_KEY'].present? || ENV['LIBRE_TRANSLATE_ENDPOINT'].present?
  19. end
  20. def supported?(_source_language, _target_language)
  21. false
  22. end
  23. def translate(_text, _source_language, _target_language)
  24. raise NotImplementedError
  25. end
  26. end