1
0
Fork 0
mirror of https://github.com/mastodon/mastodon.git synced 2024-08-20 21:08:15 -07:00
This commit is contained in:
Matt Jankowski 2024-07-31 14:07:11 +00:00 committed by GitHub
commit ad656aed51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 5 deletions

View file

@ -8,17 +8,27 @@ class TranslationService
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'])
if configuration.deepl[:api_key].present?
TranslationService::DeepL.new(
configuration.deepl[:plan],
configuration.deepl[:api_key]
)
elsif configuration.libre_translate[:endpoint].present?
TranslationService::LibreTranslate.new(
configuration.libre_translate[:endpoint],
configuration.libre_translate[:api_key]
)
else
raise NotConfiguredError
end
end
def self.configured?
ENV['DEEPL_API_KEY'].present? || ENV['LIBRE_TRANSLATE_ENDPOINT'].present?
configuration.deepl[:api_key].present? || configuration.libre_translate[:endpoint].present?
end
def self.configuration
Rails.configuration.x.translation
end
def languages

View file

@ -112,6 +112,8 @@ module Mastodon
end
end
config.x.translation = config_for(:translation)
config.to_prepare do
Doorkeeper::AuthorizationsController.layout 'modal'
Doorkeeper::AuthorizedApplicationsController.layout 'admin'

7
config/translation.yml Normal file
View file

@ -0,0 +1,7 @@
shared:
deepl:
api_key: <%= ENV.fetch('DEEPL_API_KEY', nil) %>
plan: <%= ENV.fetch('DEEPL_PLAN', 'free') %>
libre_translate:
api_key: <%= ENV.fetch('LIBRE_TRANSLATE_API_KEY', nil) %>
endpoint: <%= ENV.fetch('LIBRE_TRANSLATE_ENDPOINT', nil) %>