Translate to regional language variant (e.g. pt-BR) (#32428)
This commit is contained in:
parent
6a39212b02
commit
227d46883f
3 changed files with 21 additions and 4 deletions
|
@ -23,6 +23,6 @@ class Api::V1::Statuses::TranslationsController < Api::V1::Statuses::BaseControl
|
|||
private
|
||||
|
||||
def set_translation
|
||||
@translation = TranslateStatusService.new.call(@status, content_locale)
|
||||
@translation = TranslateStatusService.new.call(@status, I18n.locale.to_s)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,6 +9,8 @@ class TranslateStatusService < BaseService
|
|||
def call(status, target_language)
|
||||
@status = status
|
||||
@source_texts = source_texts
|
||||
|
||||
target_language = target_language.split(/[_-]/).first unless target_languages.include?(target_language)
|
||||
@target_language = target_language
|
||||
|
||||
raise Mastodon::NotPermittedError unless permitted?
|
||||
|
@ -32,11 +34,15 @@ class TranslateStatusService < BaseService
|
|||
def permitted?
|
||||
return false unless @status.distributable? && TranslationService.configured?
|
||||
|
||||
languages[@status.language]&.include?(@target_language)
|
||||
target_languages.include?(@target_language)
|
||||
end
|
||||
|
||||
def languages
|
||||
Rails.cache.fetch('translation_service/languages', expires_in: 7.days, race_condition_ttl: 1.hour) { TranslationService.configured.languages }
|
||||
Rails.cache.fetch('translation_service/languages', expires_in: 7.days, race_condition_ttl: 1.hour) { translation_backend.languages }
|
||||
end
|
||||
|
||||
def target_languages
|
||||
languages[@status.language] || []
|
||||
end
|
||||
|
||||
def content_hash
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue