Allow selecting default posting language instead of auto-detect (#7828)

* Allow selecting default posting language instead of auto-detect

* Enable default language setting in credentials API

* Fix form saving
remotes/1727458204337373841/tmp_refs/heads/signup-info-prompt
Eugen Rochko 2018-06-17 18:57:31 +02:00 committed by GitHub
parent bb21c6414d
commit a58ec29631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 19 additions and 3 deletions

View File

@ -32,6 +32,7 @@ class Api::V1::Accounts::CredentialsController < Api::BaseController
{ {
'setting_default_privacy' => source_params.fetch(:privacy, @account.user.setting_default_privacy), 'setting_default_privacy' => source_params.fetch(:privacy, @account.user.setting_default_privacy),
'setting_default_sensitive' => source_params.fetch(:sensitive, @account.user.setting_default_sensitive), 'setting_default_sensitive' => source_params.fetch(:sensitive, @account.user.setting_default_sensitive),
'setting_default_language' => source_params.fetch(:language, @account.user.setting_default_language),
} }
end end
end end

View File

@ -35,6 +35,7 @@ class Settings::PreferencesController < ApplicationController
params.require(:user).permit( params.require(:user).permit(
:setting_default_privacy, :setting_default_privacy,
:setting_default_sensitive, :setting_default_sensitive,
:setting_default_language,
:setting_unfollow_modal, :setting_unfollow_modal,
:setting_boost_modal, :setting_boost_modal,
:setting_delete_modal, :setting_delete_modal,

View File

@ -140,6 +140,8 @@ code {
} }
.input.with_block_label { .input.with_block_label {
padding-top: 15px;
& > label { & > label {
font-family: inherit; font-family: inherit;
font-size: 16px; font-size: 16px;

View File

@ -19,6 +19,7 @@ class UserSettingsDecorator
user.settings['interactions'] = merged_interactions if change?('interactions') user.settings['interactions'] = merged_interactions if change?('interactions')
user.settings['default_privacy'] = default_privacy_preference if change?('setting_default_privacy') user.settings['default_privacy'] = default_privacy_preference if change?('setting_default_privacy')
user.settings['default_sensitive'] = default_sensitive_preference if change?('setting_default_sensitive') user.settings['default_sensitive'] = default_sensitive_preference if change?('setting_default_sensitive')
user.settings['default_language'] = default_language_preference if change?('setting_default_language')
user.settings['unfollow_modal'] = unfollow_modal_preference if change?('setting_unfollow_modal') user.settings['unfollow_modal'] = unfollow_modal_preference if change?('setting_unfollow_modal')
user.settings['boost_modal'] = boost_modal_preference if change?('setting_boost_modal') user.settings['boost_modal'] = boost_modal_preference if change?('setting_boost_modal')
user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal') user.settings['delete_modal'] = delete_modal_preference if change?('setting_delete_modal')
@ -87,6 +88,10 @@ class UserSettingsDecorator
settings['setting_theme'] settings['setting_theme']
end end
def default_language_preference
settings['setting_default_language']
end
def boolean_cast_setting(key) def boolean_cast_setting(key)
ActiveModel::Type::Boolean.new.cast(settings[key]) ActiveModel::Type::Boolean.new.cast(settings[key])
end end

View File

@ -89,7 +89,7 @@ class User < ApplicationRecord
delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal, delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal,
:reduce_motion, :system_font_ui, :noindex, :theme, :display_sensitive_media, :hide_network, :reduce_motion, :system_font_ui, :noindex, :theme, :display_sensitive_media, :hide_network,
to: :settings, prefix: :setting, allow_nil: false :default_language, to: :settings, prefix: :setting, allow_nil: false
attr_accessor :invite_code attr_accessor :invite_code

View File

@ -9,6 +9,7 @@ class REST::CredentialAccountSerializer < REST::AccountSerializer
{ {
privacy: user.setting_default_privacy, privacy: user.setting_default_privacy,
sensitive: user.setting_default_sensitive, sensitive: user.setting_default_sensitive,
language: user.setting_default_language,
note: object.note, note: object.note,
fields: object.fields.map(&:to_h), fields: object.fields.map(&:to_h),
} }

View File

@ -30,7 +30,7 @@ class PostStatusService < BaseService
sensitive: (options[:sensitive].nil? ? account.user&.setting_default_sensitive : options[:sensitive]) || options[:spoiler_text].present?, sensitive: (options[:sensitive].nil? ? account.user&.setting_default_sensitive : options[:sensitive]) || options[:spoiler_text].present?,
spoiler_text: options[:spoiler_text] || '', spoiler_text: options[:spoiler_text] || '',
visibility: options[:visibility] || account.user&.setting_default_privacy, visibility: options[:visibility] || account.user&.setting_default_privacy,
language: language_from_option(options[:language]) || LanguageDetector.instance.detect(text, account), language: language_from_option(options[:language]) || account.user&.setting_default_language&.presence || LanguageDetector.instance.detect(text, account),
application: options[:application]) application: options[:application])
end end

View File

@ -12,6 +12,8 @@
.fields-group .fields-group
= f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, selected: I18n.locale = f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, selected: I18n.locale
= f.input :setting_default_language, collection: [nil] + filterable_languages.sort, wrapper: :with_label, label_method: lambda { |locale| locale.nil? ? I18n.t('statuses.language_detection') : human_locale(locale) }, required: false, include_blank: false
= f.input :chosen_languages, collection: filterable_languages.sort, wrapper: :with_block_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' = f.input :chosen_languages, collection: filterable_languages.sort, wrapper: :with_block_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li'
%h4= t 'preferences.publishing' %h4= t 'preferences.publishing'

View File

@ -675,6 +675,7 @@ en:
disallowed_hashtags: disallowed_hashtags:
one: 'contained a disallowed hashtag: %{tags}' one: 'contained a disallowed hashtag: %{tags}'
other: 'contained the disallowed hashtags: %{tags}' other: 'contained the disallowed hashtags: %{tags}'
language_detection: Automatically detect language
open_in_web: Open in web open_in_web: Open in web
over_character_limit: character limit of %{max} exceeded over_character_limit: character limit of %{max} exceeded
pin_errors: pin_errors:

View File

@ -12,10 +12,12 @@ en:
other: <span class="name-counter">%{count}</span> characters left other: <span class="name-counter">%{count}</span> characters left
fields: You can have up to 4 items displayed as a table on your profile fields: You can have up to 4 items displayed as a table on your profile
header: PNG, GIF or JPG. At most 2MB. Will be downscaled to 700x335px header: PNG, GIF or JPG. At most 2MB. Will be downscaled to 700x335px
locale: The language of the user interface, e-mails and push notifications
locked: Requires you to manually approve followers locked: Requires you to manually approve followers
note: note:
one: <span class="note-counter">1</span> character left one: <span class="note-counter">1</span> character left
other: <span class="note-counter">%{count}</span> characters left other: <span class="note-counter">%{count}</span> characters left
setting_default_language: The language of your toots can be detected automatically, but it's not always accurate
setting_hide_network: Who you follow and who follows you will not be shown on your profile setting_hide_network: Who you follow and who follows you will not be shown on your profile
setting_noindex: Affects your public profile and status pages setting_noindex: Affects your public profile and status pages
setting_theme: Affects how Mastodon looks when you're logged in from any device. setting_theme: Affects how Mastodon looks when you're logged in from any device.
@ -24,7 +26,7 @@ en:
sessions: sessions:
otp: 'Enter the two-factor code generated by your phone app or use one of your recovery codes:' otp: 'Enter the two-factor code generated by your phone app or use one of your recovery codes:'
user: user:
chosen_languages: Only toots in selected languages will be displayed in public timelines. Select nothing to see toots in all languages chosen_languages: When checked, only toots in selected languages will be displayed in public timelines
labels: labels:
account: account:
fields: fields:
@ -53,6 +55,7 @@ en:
password: Password password: Password
setting_auto_play_gif: Auto-play animated GIFs setting_auto_play_gif: Auto-play animated GIFs
setting_boost_modal: Show confirmation dialog before boosting setting_boost_modal: Show confirmation dialog before boosting
setting_default_language: Posting language
setting_default_privacy: Post privacy setting_default_privacy: Post privacy
setting_default_sensitive: Always mark media as sensitive setting_default_sensitive: Always mark media as sensitive
setting_delete_modal: Show confirmation dialog before deleting a toot setting_delete_modal: Show confirmation dialog before deleting a toot