Add user locale setting
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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') }
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user