about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/forms.scss16
-rw-r--r--app/controllers/application_controller.rb7
-rw-r--r--app/controllers/settings/preferences_controller.rb4
-rw-r--r--app/mailers/notification_mailer.rb20
-rw-r--r--app/models/user.rb1
-rw-r--r--app/views/settings/preferences/show.html.haml2
6 files changed, 39 insertions, 11 deletions
diff --git a/app/assets/stylesheets/forms.scss b/app/assets/stylesheets/forms.scss
index ad2e30b61..306f474d6 100644
--- a/app/assets/stylesheets/forms.scss
+++ b/app/assets/stylesheets/forms.scss
@@ -14,20 +14,23 @@ code {
     margin-bottom: 15px;
   }
 
-  .input.file {
+  .input.file, .input.select {
     padding: 15px 0;
     margin-bottom: 0;
+    display: flex;
 
     label {
       font-family: 'Roboto';
       font-size: 16px;
       color: #fff;
       width: 100px;
-      display: inline-block;
+      display: block;
+      flex: 0 0 auto;
+      padding-top: 5px;
     }
 
-    input[type=file] {
-      width: 280px;
+    input[type=file], select {
+      flex: 1 1 auto;
     }
   }
 
@@ -42,11 +45,14 @@ code {
       font-family: 'Roboto';
       font-size: 14px;
       color: #9baec8;
+      display: block;
     }
 
     input[type=checkbox] {
       display: inline-block;
-      margin-bottom: -13px;
+      position: relative;
+      top: 3px;
+      margin-right: 8px;
     }
   }
 
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index c7a99b22f..f9aeb127a 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -13,6 +13,7 @@ class ApplicationController < ActionController::Base
   rescue_from ActiveRecord::RecordNotFound, with: :not_found
 
   before_action :store_current_location, except: :raise_not_found, unless: :devise_controller?
+  before_action :set_locale, if: 'user_signed_in?'
 
   def raise_not_found
     raise ActionController::RoutingError, "No route matches #{params[:unmatched_route]}"
@@ -24,6 +25,12 @@ class ApplicationController < ActionController::Base
     store_location_for(:user, request.url)
   end
 
+  def set_locale
+    I18n.locale = current_user.locale || I18n.default_locale
+  rescue I18n::InvalidLocale
+    I18n.locale = I18n.default_locale
+  end
+
   protected
 
   def not_found
diff --git a/app/controllers/settings/preferences_controller.rb b/app/controllers/settings/preferences_controller.rb
index 4dc2cd61f..5be8719ae 100644
--- a/app/controllers/settings/preferences_controller.rb
+++ b/app/controllers/settings/preferences_controller.rb
@@ -14,7 +14,7 @@ class Settings::PreferencesController < ApplicationController
     current_user.settings(:notification_emails).favourite = user_params[:notification_emails][:favourite] == '1'
     current_user.settings(:notification_emails).mention   = user_params[:notification_emails][:mention]   == '1'
 
-    if current_user.save
+    if current_user.update(user_params.except(:notification_emails))
       redirect_to settings_preferences_path, notice: I18n.t('generic.changes_saved_msg')
     else
       render action: :show
@@ -24,6 +24,6 @@ class Settings::PreferencesController < ApplicationController
   private
 
   def user_params
-    params.require(:user).permit(notification_emails: [:follow, :reblog, :favourite, :mention])
+    params.require(:user).permit(:locale, notification_emails: [:follow, :reblog, :favourite, :mention])
   end
 end
diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb
index 33bea4c79..cf5ad3f92 100644
--- a/app/mailers/notification_mailer.rb
+++ b/app/mailers/notification_mailer.rb
@@ -8,7 +8,10 @@ class NotificationMailer < ApplicationMailer
     @status = status
 
     return unless @me.user.settings(:notification_emails).mention
-    mail to: @me.user.email, subject: I18n.t('notification_mailer.mention.subject', name: @status.account.acct)
+
+    I18n.with_locale(@me.user.locale || I18n.default_locale) do
+      mail to: @me.user.email, subject: I18n.t('notification_mailer.mention.subject', name: @status.account.acct)
+    end
   end
 
   def follow(followed_account, follower)
@@ -16,7 +19,10 @@ class NotificationMailer < ApplicationMailer
     @account = follower
 
     return unless @me.user.settings(:notification_emails).follow
-    mail to: @me.user.email, subject: I18n.t('notification_mailer.follow.subject', name: @account.acct)
+
+    I18n.with_locale(@me.user.locale || I18n.default_locale) do
+      mail to: @me.user.email, subject: I18n.t('notification_mailer.follow.subject', name: @account.acct)
+    end
   end
 
   def favourite(target_status, from_account)
@@ -25,7 +31,10 @@ class NotificationMailer < ApplicationMailer
     @status  = target_status
 
     return unless @me.user.settings(:notification_emails).favourite
-    mail to: @me.user.email, subject: I18n.t('notification_mailer.favourite.subject', name: @account.acct)
+
+    I18n.with_locale(@me.user.locale || I18n.default_locale) do
+      mail to: @me.user.email, subject: I18n.t('notification_mailer.favourite.subject', name: @account.acct)
+    end
   end
 
   def reblog(target_status, from_account)
@@ -34,6 +43,9 @@ class NotificationMailer < ApplicationMailer
     @status  = target_status
 
     return unless @me.user.settings(:notification_emails).reblog
-    mail to: @me.user.email, subject: I18n.t('notification_mailer.reblog.subject', name: @account.acct)
+
+    I18n.with_locale(@me.user.locale || I18n.default_locale) do
+      mail to: @me.user.email, subject: I18n.t('notification_mailer.reblog.subject', name: @account.acct)
+    end
   end
 end
diff --git a/app/models/user.rb b/app/models/user.rb
index 4a330d8ea..4eb1d20a5 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -7,6 +7,7 @@ class User < ApplicationRecord
   accepts_nested_attributes_for :account
 
   validates :account, presence: true
+  validates :locale, inclusion: I18n.available_locales.map(&:to_s), unless: 'locale.nil?'
 
   scope :prolific, -> { joins('inner join statuses on statuses.account_id = users.account_id').select('users.*, count(statuses.id) as statuses_count').group('users.id').order('statuses_count desc') }
   scope :recent,   -> { order('id desc') }
diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml
index 21a6dbd5d..60608136f 100644
--- a/app/views/settings/preferences/show.html.haml
+++ b/app/views/settings/preferences/show.html.haml
@@ -4,6 +4,8 @@
 = simple_form_for current_user, url: settings_preferences_path, html: { method: :put } do |f|
   = render 'shared/error_messages', object: current_user
 
+  = f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false
+
   = f.simple_fields_for :notification_emails, current_user.settings(:notification_emails) do |ff|
     = ff.input :follow, as: :boolean, wrapper: :with_label
     = ff.input :reblog, as: :boolean, wrapper: :with_label