about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-06-17 18:57:31 +0200
committerGitHub <noreply@github.com>2018-06-17 18:57:31 +0200
commita58ec29631f74259364dc71b408a8d66df657149 (patch)
treeedc8613a80d7e762d96f2ea1a25273276618aa32
parentbb21c6414db64739637b4ea81526efe8e539cce0 (diff)
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
-rw-r--r--app/controllers/api/v1/accounts/credentials_controller.rb1
-rw-r--r--app/controllers/settings/preferences_controller.rb1
-rw-r--r--app/javascript/styles/mastodon/forms.scss2
-rw-r--r--app/lib/user_settings_decorator.rb5
-rw-r--r--app/models/user.rb2
-rw-r--r--app/serializers/rest/credential_account_serializer.rb1
-rw-r--r--app/services/post_status_service.rb2
-rw-r--r--app/views/settings/preferences/show.html.haml2
-rw-r--r--config/locales/en.yml1
-rw-r--r--config/locales/simple_form.en.yml5
10 files changed, 19 insertions, 3 deletions
diff --git a/app/controllers/api/v1/accounts/credentials_controller.rb b/app/controllers/api/v1/accounts/credentials_controller.rb
index 259d07be8..2d0737ee4 100644
--- a/app/controllers/api/v1/accounts/credentials_controller.rb
+++ b/app/controllers/api/v1/accounts/credentials_controller.rb
@@ -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_sensitive' => source_params.fetch(:sensitive, @account.user.setting_default_sensitive),
+      'setting_default_language' => source_params.fetch(:language, @account.user.setting_default_language),
     }
   end
 end
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index 851e62d1b..e2cb13167 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -35,6 +35,7 @@ class Settings::PreferencesController < ApplicationController
     params.require(:user).permit(
       :setting_default_privacy,
       :setting_default_sensitive,
+      :setting_default_language,
       :setting_unfollow_modal,
       :setting_boost_modal,
       :setting_delete_modal,
diff --git a/app/javascript/styles/mastodon/forms.scss b/app/javascript/styles/mastodon/forms.scss
index de16784a8..f1ed2c90b 100644
--- a/app/javascript/styles/mastodon/forms.scss
+++ b/app/javascript/styles/mastodon/forms.scss
@@ -140,6 +140,8 @@ code {
   }
 
   .input.with_block_label {
+    padding-top: 15px;
+
     & > label {
       font-family: inherit;
       font-size: 16px;
diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb
index a82f8974b..833959397 100644
--- a/app/lib/user_settings_decorator.rb
+++ b/app/lib/user_settings_decorator.rb
@@ -19,6 +19,7 @@ class UserSettingsDecorator
     user.settings['interactions']            = merged_interactions if change?('interactions')
     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_language']        = default_language_preference if change?('setting_default_language')
     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['delete_modal']            = delete_modal_preference if change?('setting_delete_modal')
@@ -87,6 +88,10 @@ class UserSettingsDecorator
     settings['setting_theme']
   end
 
+  def default_language_preference
+    settings['setting_default_language']
+  end
+
   def boolean_cast_setting(key)
     ActiveModel::Type::Boolean.new.cast(settings[key])
   end
diff --git a/app/models/user.rb b/app/models/user.rb
index c95960dc6..c820c553a 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -89,7 +89,7 @@ class User < ApplicationRecord
 
   delegate :auto_play_gif, :default_sensitive, :unfollow_modal, :boost_modal, :delete_modal,
            :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
 
diff --git a/app/serializers/rest/credential_account_serializer.rb b/app/serializers/rest/credential_account_serializer.rb
index 56857cba8..fb195eb07 100644
--- a/app/serializers/rest/credential_account_serializer.rb
+++ b/app/serializers/rest/credential_account_serializer.rb
@@ -9,6 +9,7 @@ class REST::CredentialAccountSerializer < REST::AccountSerializer
     {
       privacy: user.setting_default_privacy,
       sensitive: user.setting_default_sensitive,
+      language: user.setting_default_language,
       note: object.note,
       fields: object.fields.map(&:to_h),
     }
diff --git a/app/services/post_status_service.rb b/app/services/post_status_service.rb
index a5a21c359..735985725 100644
--- a/app/services/post_status_service.rb
+++ b/app/services/post_status_service.rb
@@ -30,7 +30,7 @@ class PostStatusService < BaseService
                                         sensitive: (options[:sensitive].nil? ? account.user&.setting_default_sensitive : options[:sensitive]) || options[:spoiler_text].present?,
                                         spoiler_text: options[:spoiler_text] || '',
                                         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])
     end
 
diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml
index 6ec03ab4b..43430069f 100644
--- a/app/views/settings/preferences/show.html.haml
+++ b/app/views/settings/preferences/show.html.haml
@@ -12,6 +12,8 @@
   .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 :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'
 
   %h4= t 'preferences.publishing'
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 46875d2ec..01e5dd2f8 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -675,6 +675,7 @@ en:
     disallowed_hashtags:
       one: 'contained a disallowed hashtag: %{tags}'
       other: 'contained the disallowed hashtags: %{tags}'
+    language_detection: Automatically detect language
     open_in_web: Open in web
     over_character_limit: character limit of %{max} exceeded
     pin_errors:
diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml
index a75a0f567..6783f0045 100644
--- a/config/locales/simple_form.en.yml
+++ b/config/locales/simple_form.en.yml
@@ -12,10 +12,12 @@ en:
           other: <span class="name-counter">%{count}</span> characters left
         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
+        locale: The language of the user interface, e-mails and push notifications
         locked: Requires you to manually approve followers
         note:
           one: <span class="note-counter">1</span> character 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_noindex: Affects your public profile and status pages
         setting_theme: Affects how Mastodon looks when you're logged in from any device.
@@ -24,7 +26,7 @@ en:
       sessions:
         otp: 'Enter the two-factor code generated by your phone app or use one of your recovery codes:'
       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:
       account:
         fields:
@@ -53,6 +55,7 @@ en:
         password: Password
         setting_auto_play_gif: Auto-play animated GIFs
         setting_boost_modal: Show confirmation dialog before boosting
+        setting_default_language: Posting language
         setting_default_privacy: Post privacy
         setting_default_sensitive: Always mark media as sensitive
         setting_delete_modal: Show confirmation dialog before deleting a toot