Skip to content

Commit b083196

Browse files
committed
* add i18n for devise and rails_admin
* update devise views for rails_admin login
1 parent ab8b0dc commit b083196

File tree

17 files changed

+482
-102
lines changed

17 files changed

+482
-102
lines changed

Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ ruby '2.6.5'
77

88
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
99
gem 'rails', '~> 6.0.3'
10+
gem 'rails-i18n', '~> 6.0.0'
1011

1112
# Use postgresql as the database for Active Record
1213
gem 'pg'
1314

1415
gem 'bcrypt', '~> 3.1.7' # Use ActiveModel has_secure_password
1516
gem 'devise' # Use devise as authentication module
16-
gem 'graphql'
17+
gem 'devise-i18n' # Install default translations
18+
gem 'graphql' # GraphQL as API
1719
gem 'graphql-auth', git: '[email protected]:simonfranzen/graphql-auth.git', branch: 'rails6'
1820
gem 'graphql-errors' # GrapqhQL error handling
1921
gem 'rack-cors' # Rack CORS settings
2022
gem 'rails_admin', '~> 2.0.2' # Admin interface
23+
gem 'rails_admin-i18n' # Use default rails_admin translations
2124
gem 'cancancan' # Defining abilities
2225
gem 'image_processing', '~> 1.2' # Image processing
2326
gem 'mini_magick' # Image manipulation with rmagick
@@ -62,6 +65,7 @@ group :test do
6265
gem 'rails-controller-testing'
6366
gem 'shoulda-matchers', '4.0.0.rc1'
6467
gem 'simplecov', require: false
68+
gem 'i18n-spec'
6569
end
6670

6771
group :development do

Gemfile.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ GEM
9191
railties (>= 4.1.0)
9292
responders
9393
warden (~> 1.2.3)
94+
devise-i18n (1.9.2)
95+
devise (>= 4.7.1)
9496
diff-lcs (1.3)
9597
docile (1.3.2)
9698
dotenv (2.7.2)
@@ -122,9 +124,13 @@ GEM
122124
tilt
123125
i18n (1.8.5)
124126
concurrent-ruby (~> 1.0)
127+
i18n-spec (0.6.0)
128+
iso
125129
image_processing (1.11.0)
126130
mini_magick (>= 4.9.5, < 5)
127131
ruby-vips (>= 2.0.17, < 3)
132+
iso (0.3.0)
133+
i18n
128134
jquery-rails (4.4.0)
129135
rails-dom-testing (>= 1, < 3)
130136
railties (>= 4.2.0)
@@ -208,6 +214,9 @@ GEM
208214
nokogiri (>= 1.6)
209215
rails-html-sanitizer (1.3.0)
210216
loofah (~> 2.3)
217+
rails-i18n (6.0.0)
218+
i18n (>= 0.7, < 2)
219+
railties (>= 6.0.0, < 7)
211220
rails_admin (2.0.2)
212221
activemodel-serializers-xml (>= 1.0)
213222
builder (~> 3.1)
@@ -220,6 +229,7 @@ GEM
220229
rails (>= 5.0, < 7)
221230
remotipart (~> 1.3)
222231
sassc-rails (>= 1.3, < 3)
232+
rails_admin-i18n (1.12.0)
223233
railties (6.0.3.3)
224234
actionpack (= 6.0.3.3)
225235
activesupport (= 6.0.3.3)
@@ -343,12 +353,14 @@ DEPENDENCIES
343353
cancancan
344354
database_cleaner (~> 1.6)
345355
devise
356+
devise-i18n
346357
dotenv-rails
347358
factory_bot_rails
348359
faker (~> 1.8)
349360
graphql
350361
graphql-auth!
351362
graphql-errors
363+
i18n-spec
352364
image_processing (~> 1.2)
353365
listen (>= 3.0.5, < 3.2)
354366
mini_magick
@@ -357,7 +369,9 @@ DEPENDENCIES
357369
rack-cors
358370
rails (~> 6.0.3)
359371
rails-controller-testing
372+
rails-i18n (~> 6.0.0)
360373
rails_admin (~> 2.0.2)
374+
rails_admin-i18n
361375
rspec-rails (~> 3.8)
362376
rubocop
363377
rubocop-performance

app/views/devise/confirmations/new.html.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
<%= image_tag('logo.svg', width: '200px', alt: 'Logo' ) %>
44
</div>
55
<hr/>
6-
<h2>Resend confirmation instructions</h2>
6+
<h2><%= t('.resend_confirmation_instructions') %></h2>
77

8-
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
8+
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
99
<%= render "devise/shared/error_messages", resource: resource %>
10-
<%= f.hidden_field :reset_password_token %>
1110

1211
<div class="field">
1312
<%= f.label :email %><br />
1413
<%= f.email_field :email, autofocus: true, autocomplete: "email", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
1514
</div>
1615

1716
<div class="actions">
18-
<%= f.submit "Resend confirmation instructions" %>
17+
<%= f.submit t('.resend_confirmation_instructions') %>
1918
</div>
2019
<% end %>
2120

2221
<%= render "devise/shared/links" %>
22+
2323
</div>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
<p>Hello <%= @resource.email %>!</p>
1+
<p><%= t('.greeting', recipient: @resource.email) %></p>
22

3-
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
3+
<p><%= t('.message') %></p>
44

5-
<p>Click the link below to unlock your account:</p>
5+
<p><%= t('.instruction') %></p>
66

7-
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
7+
<p><%= link_to t('.action'), unlock_url(@resource, unlock_token: @token) %></p>

app/views/devise/passwords/edit.html.erb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,30 @@
33
<%= image_tag('logo.svg', width: '200px', alt: 'Logo' ) %>
44
</div>
55
<hr/>
6-
<h2>Passwort ändern</h2>
6+
<h2><%= t('.change_your_password') %></h2>
77

88
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
99
<%= render "devise/shared/error_messages", resource: resource %>
1010
<%= f.hidden_field :reset_password_token %>
1111

1212
<div class="field">
13-
<%= f.password_field :password, autofocus: true, autocomplete: "new-password", placeholder: 'Neues Passwort' %>
13+
<%= f.label :password, t('.new_password') %><br />
14+
<% if @minimum_password_length %>
15+
<em><%= t('devise.shared.minimum_password_length', count: @minimum_password_length) %></em><br />
16+
<% end %>
17+
<%= f.password_field :password, autofocus: true, autocomplete: "new-password" %>
1418
</div>
1519

1620
<div class="field">
17-
<%= f.password_field :password_confirmation, autocomplete: "off", placeholder: 'Passwort bestätigen' %>
21+
<%= f.label :password_confirmation, t('.confirm_new_password') %><br />
22+
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
1823
</div>
1924

2025
<div class="actions">
21-
<%= f.submit "Neues Passwort speichern" %>
26+
<%= f.submit t('.change_my_password') %>
2227
</div>
2328
<% end %>
2429

2530
<%= render "devise/shared/links" %>
31+
2632
</div>
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
<div class="authWrapper">
2-
<div class='logo-wrapper'>
3-
<%= image_tag('logo.svg', width: '200px', alt: 'Logo' ) %>
4-
</div>
5-
<hr/>
6-
<h2>Passwort vergessen?</h2>
2+
<h2><%= t('.forgot_your_password') %></h2>
73

84
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
95
<%= render "devise/shared/error_messages", resource: resource %>
106

117
<div class="field">
12-
<%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: 'E-Mail' %>
8+
<%= f.label :email %><br />
9+
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
1310
</div>
1411

1512
<div class="actions">
16-
<%= f.submit "Passwort zurücksetzen" %>
13+
<%= f.submit t('.send_me_reset_password_instructions') %>
1714
</div>
1815
<% end %>
1916

2017
<%= render "devise/shared/links" %>
18+
2119
</div>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<%# Note that registration is currently not used #%>
2+
<div class="authWrapper">
3+
<div class='logo-wrapper'>
4+
<%= image_tag('logo.svg', width: '200px', alt: 'Logo' ) %>
5+
</div>
6+
<hr/>
7+
<h2><%= t('.title', resource: resource.model_name.human) %></h2>
8+
9+
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
10+
<%= render "devise/shared/error_messages", resource: resource %>
11+
12+
<div class="field">
13+
<%= f.label :email %><br />
14+
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
15+
</div>
16+
17+
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
18+
<div><%= t('.currently_waiting_confirmation_for_email', email: resource.unconfirmed_email) %></div>
19+
<% end %>
20+
21+
<div class="field">
22+
<%= f.label :password %> <i>(<%= t('.leave_blank_if_you_don_t_want_to_change_it') %>)</i><br />
23+
<%= f.password_field :password, autocomplete: "new-password" %>
24+
<% if @minimum_password_length %>
25+
<br />
26+
<em><%= t('devise.shared.minimum_password_length', count: @minimum_password_length) %></em>
27+
<% end %>
28+
</div>
29+
30+
<div class="field">
31+
<%= f.label :password_confirmation %><br />
32+
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
33+
</div>
34+
35+
<div class="field">
36+
<%= f.label :current_password %> <i>(<%= t('.we_need_your_current_password_to_confirm_your_changes') %>)</i><br />
37+
<%= f.password_field :current_password, autocomplete: "current-password" %>
38+
</div>
39+
40+
<div class="actions">
41+
<%= f.submit t('.update') %>
42+
</div>
43+
<% end %>
44+
45+
<h3><%= t('.cancel_my_account') %></h3>
46+
47+
<p><%= t('.unhappy') %> <%= button_to t('.cancel_my_account'), registration_path(resource_name), data: { confirm: t('.are_you_sure') }, method: :delete %></p>
48+
49+
<%= link_to t('devise.shared.links.back'), :back %>
50+
</div>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<%# Note that registration is currently not used #%>
2+
<div class="authWrapper">
3+
<div class='logo-wrapper'>
4+
<%= image_tag('logo.svg', width: '200px', alt: 'Logo' ) %>
5+
</div>
6+
<hr/>
7+
<h2><%= t('.sign_up') %></h2>
8+
9+
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
10+
<%= render "devise/shared/error_messages", resource: resource %>
11+
12+
<div class="field">
13+
<%= f.label :email %><br />
14+
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
15+
</div>
16+
17+
<div class="field">
18+
<%= f.label :password %>
19+
<% if @minimum_password_length %>
20+
<em><%= t('devise.shared.minimum_password_length', count: @minimum_password_length) %></em>
21+
<% end %><br />
22+
<%= f.password_field :password, autocomplete: "new-password" %>
23+
</div>
24+
25+
<div class="field">
26+
<%= f.label :password_confirmation %><br />
27+
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
28+
</div>
29+
30+
<div class="actions">
31+
<%= f.submit t('.sign_up') %>
32+
</div>
33+
<% end %>
34+
35+
<%= render "devise/shared/links" %>
36+
</div>

app/views/devise/sessions/new.html.erb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
<%= image_tag('logo.svg', width: '200px', alt: 'Logo' ) %>
44
</div>
55
<hr/>
6-
<h2>Login</h2>
6+
<h2><%= t('.sign_in') %></h2>
7+
78
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
89
<div class="field">
9-
<%= f.email_field :email, autofocus: true, autocomplete: "email", placeholder: 'E-Mail' %>
10+
<%= f.label :email %><br />
11+
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
1012
</div>
1113

1214
<div class="field">
13-
<%= f.password_field :password, autocomplete: "current-password", placeholder: 'Passwort' %>
15+
<%= f.label :password %><br />
16+
<%= f.password_field :password, autocomplete: "current-password" %>
1417
</div>
1518

1619
<% if devise_mapping.rememberable? %>
@@ -21,9 +24,10 @@
2124
<% end %>
2225

2326
<div class="actions">
24-
<%= f.submit "Anmelden" %>
27+
<%= f.submit t('.sign_in') %>
2528
</div>
2629
<% end %>
2730

2831
<%= render "devise/shared/links" %>
32+
2933
</div>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
<%- if controller_name != 'sessions' %>
2-
<%= link_to "Anmelden", new_session_path(resource_name) %><br />
2+
<%= link_to t(".sign_in"), new_session_path(resource_name) %><br />
33
<% end %>
44

5-
<%# disable registration because we use this views just to get into rails admin backend %>
5+
<%# remove registration %>
66
<%# if devise_mapping.registerable? && controller_name != 'registrations' %>
7-
<%# link_to "Registrieren", new_registration_path(resource_name) %><br />
7+
<%# link_to t(".sign_up"), new_registration_path(resource_name) %><br />
88
<%# end %>
99

1010
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
11-
<%= link_to "Passwort vergessen?", new_password_path(resource_name) %><br />
11+
<%= link_to t(".forgot_your_password"), new_password_path(resource_name) %><br />
1212
<% end %>
1313

1414
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
15-
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
15+
<%= link_to t('.didn_t_receive_confirmation_instructions'), new_confirmation_path(resource_name) %><br />
1616
<% end %>
1717

1818
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
19-
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
19+
<%= link_to t('.didn_t_receive_unlock_instructions'), new_unlock_path(resource_name) %><br />
2020
<% end %>
2121

2222
<%- if devise_mapping.omniauthable? %>
2323
<%- resource_class.omniauth_providers.each do |provider| %>
24-
<%= link_to "Sign in with #{OmniAuth::Utils.camelize(provider)}", omniauth_authorize_path(resource_name, provider) %><br />
24+
<%= link_to t('.sign_in_with_provider', provider: OmniAuth::Utils.camelize(provider)), omniauth_authorize_path(resource_name, provider) %><br />
2525
<% end %>
2626
<% end %>

0 commit comments

Comments
 (0)