git localize flashes

This commit is contained in:
pixeldesu 2015-06-07 19:03:57 +02:00
parent e6e1d03187
commit 984abbe738
5 changed files with 35 additions and 15 deletions

View File

@ -35,13 +35,13 @@ class ApplicationController < ActionController::Base
if current_user.present? && current_user.banned?
name = current_user.screen_name
# obligatory '2001: A Space Odyssey' reference
flash[:notice] = "I'm sorry, #{name}, I'm afraid I can't do that."
flash[:notice] = t('flash.ban.error', name: name)
unless current_user.ban_reason.nil?
flash[:notice] += "\nBan reason: #{current_user.ban_reason}"
flash[:notice] += "\n#{t('flash.ban.reason', reason: current_user.ban_reason)}"
end
if not current_user.permanently_banned?
# TODO format banned_until
flash[:notice] += "\nBanned until: #{current_user.banned_until}"
flash[:notice] += "\n#{t('flash.ban.until', time: current_user.banned_until)}"
end
sign_out current_user
redirect_to new_user_session_path

View File

@ -11,9 +11,9 @@ class ServicesController < ApplicationController
service = Service.initialize_from_omniauth( omniauth_hash )
if current_user.services << service
flash[:success] = 'Successfully added service'
flash[:success] = t('flash.service.create.success')
else
flash[:error] = 'Could not add service :('
flash[:error] = t('flash.service.create.error')
end
if origin
@ -25,14 +25,14 @@ class ServicesController < ApplicationController
def failure
Rails.logger.info "oauth error: #{params.inspect}"
flash[:error] = 'An error occurred'
flash[:error] = t('flash.service.failure')
redirect_to services_path
end
def destroy
@service = current_user.services.find(params[:id])
@service.destroy
flash[:success] = 'Successfully removed service'
flash[:success] = t('flash.service.destroy')
redirect_to services_path
end

View File

@ -27,12 +27,12 @@ class UserController < ApplicationController
user_attributes = params.require(:user).permit(:display_name, :profile_picture, :profile_header, :motivation_header, :website,
:location, :bio, :crop_x, :crop_y, :crop_w, :crop_h, :crop_h_x, :crop_h_y, :crop_h_w, :crop_h_h)
if current_user.update_attributes(user_attributes)
text = 'Your profile has been updated!'
text += ' It might take a few minutes until your new profile picture is shown everywhere.' if user_attributes[:profile_picture]
text += ' It might take a few minutes until your new profile header is shown everywhere.' if user_attributes[:profile_header]
text = t('flash.user.update.text')
text += t('flash.user.update.avatar') if user_attributes[:profile_picture]
text += t('flash.user.update.header') if user_attributes[:profile_header]
flash[:success] = text
else
flash[:error] = 'An error occurred. ;_;'
flash[:error] = t('flash.user.update.error')
end
redirect_to edit_user_profile_path
end
@ -48,9 +48,9 @@ class UserController < ApplicationController
:privacy_allow_stranger_answers,
:privacy_show_in_search)
if current_user.update_attributes(user_attributes)
flash[:success] = 'Your privacy settings have been updated!'
flash[:success] = t('flash.user.update_privacy.success')
else
flash[:error] = 'An error occurred. ;_;'
flash[:error] = t('flash.user.update_privacy.error')
end
redirect_to edit_user_privacy_path
end

View File

@ -1,10 +1,10 @@
%noscript
.alert.alert-danger
= t 'views.messages.noscript'
= t 'messages.noscript'
- flash.each do |key, value|
.alert.alert-dismissible{class: "alert-#{bootstrap_color key}", role: "alert"}
%button.close{type: "button", "data-dismiss" => "alert"}
%span{"aria-hidden" => "true"} &times;
%span.sr-only Close
%span.sr-only= t 'views.actions.close'
= value

View File

@ -20,6 +20,26 @@
# available at http://guides.rubyonrails.org/i18n.html.
en:
flash:
ban:
error: "I'm sorry, %{name}, I'm afraid I can't do that."
reason: "Ban reason: %{reason}"
until: "Banned until: %{time}"
service:
create:
success: "Successfully added service"
error: "Could not add service :("
failure: "An error occurred"
destroy: "Successfully removed service"
user:
update:
text: "Your profile has been updated!"
avatar: " It might take a few minutes until your new profile picture is shown everywhere."
header: " It might take a few minutes until your new profile header is shown everywhere."
error: "An error occurred. ;_;"
update_privacy:
success: "Your privacy settings have been updated!"
error: "An error occurred. ;_;"
messages:
noscript: "Please activate JavaScript."
error: "An error occurred."