diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-03-09 08:46:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-09 08:46:05 +0100 |
commit | c0327ff31f839e1beae59486bf92d7e1c4689b06 (patch) | |
tree | 37d25240f1427ed1c2ee6d62c9359d15afa1432b /app | |
parent | 8f6c67bfdeddd1c2c1085067e3dc549fb53f6ff4 (diff) |
Fix invalid language resulting in no fallback being set on statuses (#17722)
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/languages_helper.rb | 9 | ||||
-rw-r--r-- | app/services/post_status_service.rb | 2 | ||||
-rw-r--r-- | app/services/update_status_service.rb | 2 |
3 files changed, 11 insertions, 2 deletions
diff --git a/app/helpers/languages_helper.rb b/app/helpers/languages_helper.rb index f22cc6d28..9be35ad8e 100644 --- a/app/helpers/languages_helper.rb +++ b/app/helpers/languages_helper.rb @@ -241,6 +241,15 @@ module LanguagesHelper code end + def valid_locale_cascade(*arr) + arr.each do |str| + locale = valid_locale_or_nil(str) + return locale if locale.present? + end + + nil + end + def valid_locale?(locale) locale.present? && SUPPORTED_LOCALES.key?(locale.to_sym) end diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb index b3bc4a0a2..7508c3b64 100644 --- a/app/services/post_status_service.rb +++ b/app/services/post_status_service.rb @@ -162,7 +162,7 @@ class PostStatusService < BaseService sensitive: @sensitive, spoiler_text: @options[:spoiler_text] || '', visibility: @visibility, - language: valid_locale_or_nil(@options[:language].presence || @account.user&.preferred_posting_language || I18n.default_locale), + language: valid_locale_cascade(@options[:language], @account.user&.preferred_posting_language, I18n.default_locale), application: @options[:application], rate_limit: @options[:with_rate_limit], }.compact diff --git a/app/services/update_status_service.rb b/app/services/update_status_service.rb index 93203bc49..973e6ddee 100644 --- a/app/services/update_status_service.rb +++ b/app/services/update_status_service.rb @@ -94,7 +94,7 @@ class UpdateStatusService < BaseService @status.text = @options[:text].presence || @options.delete(:spoiler_text) || '' if @options.key?(:text) @status.spoiler_text = @options[:spoiler_text] || '' if @options.key?(:spoiler_text) @status.sensitive = @options[:sensitive] || @options[:spoiler_text].present? if @options.key?(:sensitive) || @options.key?(:spoiler_text) - @status.language = valid_locale_or_nil(@options[:language] || @status.language || @status.account.user&.preferred_posting_language || I18n.default_locale) + @status.language = valid_locale_cascade(@options[:language], @status.language, @status.account.user&.preferred_posting_language, I18n.default_locale) @status.edited_at = Time.now.utc @status.save! |