From 984abbe738075861ac6be13eab6dfa2c4482a559 Mon Sep 17 00:00:00 2001 From: pixeldesu Date: Sun, 7 Jun 2015 19:03:57 +0200 Subject: [PATCH] git localize flashes --- app/controllers/application_controller.rb | 6 +++--- app/controllers/services_controller.rb | 8 ++++---- app/controllers/user_controller.rb | 12 ++++++------ app/views/layouts/_messages.html.haml | 4 ++-- config/locales/en.yml | 20 ++++++++++++++++++++ 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 474d3bb4..ffaae5e1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index d49a55a5..376efc52 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -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 diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index a3d3f416..33cad9e1 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -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 diff --git a/app/views/layouts/_messages.html.haml b/app/views/layouts/_messages.html.haml index 01a8e8de..73ba513d 100644 --- a/app/views/layouts/_messages.html.haml +++ b/app/views/layouts/_messages.html.haml @@ -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"} × - %span.sr-only Close + %span.sr-only= t 'views.actions.close' = value diff --git a/config/locales/en.yml b/config/locales/en.yml index 8ebaabcc..df185fb9 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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."