mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-25 17:51:36 +01:00
Move translation service config to config_for
yml (#30663)
This commit is contained in:
parent
5a4f4f3e83
commit
35f008aa2a
3 changed files with 24 additions and 5 deletions
|
@ -8,17 +8,27 @@ class TranslationService
|
||||||
class UnexpectedResponseError < Error; end
|
class UnexpectedResponseError < Error; end
|
||||||
|
|
||||||
def self.configured
|
def self.configured
|
||||||
if ENV['DEEPL_API_KEY'].present?
|
if configuration.deepl[:api_key].present?
|
||||||
TranslationService::DeepL.new(ENV.fetch('DEEPL_PLAN', 'free'), ENV['DEEPL_API_KEY'])
|
TranslationService::DeepL.new(
|
||||||
elsif ENV['LIBRE_TRANSLATE_ENDPOINT'].present?
|
configuration.deepl[:plan],
|
||||||
TranslationService::LibreTranslate.new(ENV['LIBRE_TRANSLATE_ENDPOINT'], ENV['LIBRE_TRANSLATE_API_KEY'])
|
configuration.deepl[:api_key]
|
||||||
|
)
|
||||||
|
elsif configuration.libre_translate[:endpoint].present?
|
||||||
|
TranslationService::LibreTranslate.new(
|
||||||
|
configuration.libre_translate[:endpoint],
|
||||||
|
configuration.libre_translate[:api_key]
|
||||||
|
)
|
||||||
else
|
else
|
||||||
raise NotConfiguredError
|
raise NotConfiguredError
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.configured?
|
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
|
end
|
||||||
|
|
||||||
def languages
|
def languages
|
||||||
|
|
|
@ -109,6 +109,8 @@ module Mastodon
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.x.translation = config_for(:translation)
|
||||||
|
|
||||||
config.to_prepare do
|
config.to_prepare do
|
||||||
Doorkeeper::AuthorizationsController.layout 'modal'
|
Doorkeeper::AuthorizationsController.layout 'modal'
|
||||||
Doorkeeper::AuthorizedApplicationsController.layout 'admin'
|
Doorkeeper::AuthorizedApplicationsController.layout 'admin'
|
||||||
|
|
7
config/translation.yml
Normal file
7
config/translation.yml
Normal 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) %>
|
Loading…
Reference in a new issue