Skip to content

Commit 1ed49d0

Browse files
committed
I18n
1 parent 8e14390 commit 1ed49d0

File tree

26 files changed

+364
-233
lines changed

26 files changed

+364
-233
lines changed

app/controllers/application_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
44
protect_from_forgery with: :exception
55

66
rescue_from CanCan::AccessDenied do |exception|
7-
redirect_to root_path, :alert => "Access denied"
7+
redirect_to root_path, :alert => I18n.t('errors.access_denied')
88
end
99

1010
private
@@ -16,7 +16,7 @@ def load_project(project)
1616
@project = Project.where(id: project).first
1717
end
1818
unless @project
19-
flash[:error] = 'Project not found.'
19+
flash[:error] = I18n.t('errors.project_not_found')
2020
redirect_to projects_path
2121
end
2222
end

app/controllers/projects_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def update
5151
@project.tipping_policies_text.user = current_user
5252
end
5353
if @project.save
54-
redirect_to project_path(@project), notice: "The project settings have been updated"
54+
redirect_to project_path(@project), notice: I18n.t('notices.project_updated')
5555
else
5656
render 'edit'
5757
end
@@ -63,13 +63,13 @@ def decide_tip_amounts
6363
@project.available_amount # preload anything required to get the amount, otherwise it's loaded during the assignation and there are undesirable consequences
6464
percentages = params[:project][:tips_attributes].values.map{|tip| tip['amount_percentage'].to_f}
6565
if percentages.sum > 100
66-
redirect_to decide_tip_amounts_project_path(@project), alert: "You can't assign more than 100% of available funds."
66+
redirect_to decide_tip_amounts_project_path(@project), alert: I18n.t('errors.can_assign_more_tips')
6767
return
6868
end
6969
raise "wrong data" if percentages.min < 0
7070
@project.attributes = params.require(:project).permit(tips_attributes: [:id, :amount_percentage])
7171
if @project.save
72-
message = "The tip amounts have been defined"
72+
message = I18n.t('notices.tips_decided')
7373
if @project.has_undecided_tips?
7474
redirect_to decide_tip_amounts_project_path(@project), notice: message
7575
else
@@ -93,7 +93,7 @@ def create
9393
@project.update_repository_info repo
9494
redirect_to pretty_project_path(@project)
9595
rescue Octokit::NotFound
96-
redirect_to projects_path, alert: "Project not found"
96+
redirect_to projects_path, alert: I18n.t('errors.project_not_found')
9797
end
9898
end
9999

app/controllers/users/omniauth_callbacks_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def github
99
if @omniauth_info.primary_email.present?
1010
@user = User.create_with_omniauth!(@omniauth_info)
1111
else
12-
set_flash_message(:error, :failure, kind: 'GitHub', reason: 'your primary email address should be verified.')
12+
set_flash_message(:error, :failure, kind: 'GitHub', reason: I18n.t('devise.errors.primary_email'))
1313
redirect_to new_user_session_path and return
1414
end
1515
end
@@ -25,7 +25,7 @@ def github
2525
def load_omniauth_info
2626
@omniauth_info = request.env['omniauth.auth']['info']
2727
unless @omniauth_info
28-
set_flash_message(:error, :failure, kind: 'GitHub', reason: 'we were unable to fetch your information.')
28+
set_flash_message(:error, :failure, kind: 'GitHub', reason: I18n.t('devise.errors.omniauth_info'))
2929
redirect_to new_user_session_path and return
3030
end
3131
end

app/controllers/users_controller.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ def index
1313

1414
def update
1515
if @user.update_attributes(users_params)
16-
redirect_to @user, notice: 'Your information saved!'
16+
redirect_to @user, notice: I18n.t('notices.user_updated')
1717
else
1818
show
19-
render :show, alert: 'Error updating bitcoin address'
19+
render :show, alert: I18n.t('errors.wrong_bitcoin_address')
2020
end
2121
end
2222

@@ -26,10 +26,10 @@ def login
2626
sign_in_and_redirect @user, event: :authentication
2727
if params[:unsubscribe]
2828
@user.update unsubscribed: true
29-
flash[:alert] = 'You unsubscribed! Sorry for bothering you. Although, you still can leave us your bitcoin address to get your tips.'
29+
flash[:alert] = I18n.t('notices.user_unsubscribed')
3030
end
3131
else
32-
redirect_to root_url, alert: 'User not found'
32+
redirect_to root_url, alert: I18n.t('errors.user_not_found')
3333
end
3434
end
3535

@@ -41,14 +41,14 @@ def users_params
4141
def load_user
4242
@user = User.where(id: params[:id]).first
4343
unless @user
44-
flash[:error] = 'User not found.'
44+
flash[:error] = I18n.t('errors.user_not_found')
4545
redirect_to root_path and return
4646
end
4747
end
4848

4949
def valid_user!
5050
if current_user != @user
51-
flash[:error] = 'You are not authorized to perform this action!'
51+
flash[:error] = I18n.t('errors.access_denied')
5252
redirect_to root_path and return
5353
end
5454
end

app/models/tip.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ class Tip < ActiveRecord::Base
33
belongs_to :sendmany
44
belongs_to :project, inverse_of: :tips
55

6+
AVAILABLE_AMOUNTS = [
7+
['undecided', ""],
8+
['free', 0],
9+
['tiny', 0.1],
10+
['small', 0.5],
11+
['normal', 1],
12+
['big', 2],
13+
['huge', 5]
14+
]
15+
616
validates :amount, numericality: { greater_or_equal_than: 0, allow_nil: true }
717

818
scope :not_sent, -> { where(sendmany_id: nil) }
@@ -90,7 +100,7 @@ def amount_percentage
90100
end
91101

92102
def amount_percentage=(percentage)
93-
if undecided? and percentage.present? and %w(0 0.1 0.5 1 2 5).include?(percentage.to_s)
103+
if undecided? and percentage.present? and AVAILABLE_AMOUNTS.map(&:last).compact.map(&:to_s).include?(percentage.to_s)
94104
self.amount = (project.available_amount * (percentage.to_f / 100)).ceil
95105
end
96106
end

app/views/common/_menu.html.haml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
%ul.nav.nav-justified
22
%li{class: controller_name == 'home' ? 'active' : ''}
3-
%a{href: root_path} Home
3+
%a{href: root_path}= t('menu.home')
44
%li{class: controller_name == 'projects' || @project ? 'active' : ''}
5-
%a{href: projects_path} Supported Projects
6-
/ %li
7-
/ %a{href: "#"} About
8-
/ %li
9-
/ %a{href: "#"} Contact
5+
%a{href: projects_path}= t('menu.projects')
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
= twitter_bootstrap_form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post, class: 'form-devise' }) do |f|
2-
%h2 Resend confirmation instructions
2+
%h2= t('.title')
33
= devise_error_messages!
44
= f.email_field :email, :autofocus => true
5-
= f.submit "Resend confirmation instructions"
5+
= f.submit t('.submit')
66
%p
77
= render "devise/shared/links"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
= twitter_bootstrap_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :put, class: 'form-devise' }) do |f|
2-
%h2 Change your password
2+
%h2= t('.title')
33
= devise_error_messages!
44
= f.hidden_field :reset_password_token
55
= f.password_field :password, :autofocus => true, :autocomplete => "off"
66
= f.password_field :password_confirmation, :autocomplete => "off"
7-
= f.submit "Change my password"
7+
= f.submit t('.submit')
88
%p
99
= render "devise/shared/links"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
= twitter_bootstrap_form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post, class: 'form-devise', role: 'form' }) do |f|
2-
%h2 Forgot your password?
2+
%h2= t('.title')
33
= devise_error_messages!
44
= f.email_field :email, :autofocus => true
5-
= f.submit "Send me reset password instructions"
5+
= f.submit t('.submit')
66
%p
77
= render "devise/shared/links"
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
= twitter_bootstrap_form_for(resource, :as => resource_name, :url => registration_path(resource_name), html: { class: 'form-devise registration_form'}) do |f|
2-
%h2 Sign up
2+
%h2= t('.title')
33
= devise_error_messages!
44
= f.email_field :email, :autofocus => true
55
= f.password_field :password, :autocomplete => "off"
66
= f.password_field :password_confirmation, :autocomplete => "off"
7-
= f.submit "Sign up"
7+
= f.submit t('.submit')
88
%p
99
= render "devise/shared/links"

0 commit comments

Comments
 (0)