Skip to content

Commit 3d30048

Browse files
committed
added languages
1 parent 09665d2 commit 3d30048

24 files changed

+624
-281
lines changed

2

Whitespace-only changes.

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ gem 'mini_magick', '~> 4.5', '>= 4.5.1'
5555

5656
gem 'ransack', '~> 4.2', '>= 4.2.1'
5757

58+
gem 'i18n', '~> 1.14', '>= 1.14.5'
59+
5860
group :development, :test do
5961
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
6062
gem "debug", platforms: %i[ mri windows ]

Gemfile.lock

+1
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ DEPENDENCIES
279279
capybara
280280
debug
281281
devise (~> 4.9, >= 4.9.3)
282+
i18n (~> 1.14, >= 1.14.5)
282283
image_processing (~> 1.2)
283284
importmap-rails
284285
jbuilder
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
class ApplicationController < ActionController::Base
2+
before_action :set_locale
3+
def set_locale
4+
I18n.locale = params[:locale] || I18n.default_locale
5+
end
6+
7+
def default_url_options
8+
{locale: I18n.locale}
9+
end
210
end

app/helpers/application_helper.rb

+12-79
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,17 @@
11
module ApplicationHelper
22
def quote_of_the_day
3-
quotes = [
4-
{ text: "The only way to do great work is to love what you do.", author: "Steve Jobs" },
5-
{ text: "Life is what happens when you're busy making other plans.", author: "John Lennon" },
6-
{ text: "The future belongs to those who believe in the beauty of their dreams.", author: "Eleanor Roosevelt" },
7-
{ text: "Strive not to be a success, but rather to be of value.", author: "Albert Einstein" },
8-
{ text: "The best way to predict the future is to create it.", author: "Peter Drucker" },
9-
{ text: "The only impossible journey is the one you never begin.", author: "Tony Robbins" },
10-
{ text: "Believe you can and you're halfway there.", author: "Theodore Roosevelt" },
11-
{ text: "Do not wait to strike till the iron is hot, but make it hot by striking.", author: "William Butler Yeats" },
12-
{ text: "In three words I can sum up everything I've learned about life: it goes on.", author: "Robert Frost" },
13-
{ text: "You miss 100% of the shots you don't take.", author: "Wayne Gretzky" },
14-
{ text: "The best revenge is massive success.", author: "Frank Sinatra" },
15-
{ text: "Success usually comes to those who are too busy to be looking for it.", author: "Henry David Thoreau" },
16-
{ text: "Opportunities don't happen. You create them.", author: "Chris Grosser" },
17-
{ text: "Don't be pushed around by the fears in your mind. Be led by the dreams in your heart.", author: "Roy T. Bennett" },
18-
{ text: "You only live once, but if you do it right, once is enough.", author: "Mae West" },
19-
{ text: "The purpose of our lives is to be happy.", author: "Dalai Lama" },
20-
{ text: "Life is what happens when you're busy making other plans.", author: "John Lennon" },
21-
{ text: "The way to get started is to quit talking and begin doing.", author: "Walt Disney" },
22-
{ text: "You do not find the happy life. You make it.", author: "Camilla E. Kimball" },
23-
{ text: "Happiness is not something ready made. It comes from your own actions.", author: "Dalai Lama" },
24-
{ text: "It does not matter how slowly you go as long as you do not stop.", author: "Confucius" },
25-
{ text: "The only limit to our realization of tomorrow is our doubts of today.", author: "Franklin D. Roosevelt" },
26-
{ text: "Do what you can, with what you have, where you are.", author: "Theodore Roosevelt" },
27-
{ text: "You can never cross the ocean until you have the courage to lose sight of the shore.", author: "Christopher Columbus" },
28-
{ text: "The best time to plant a tree was 20 years ago. The second best time is now.", author: "Chinese Proverb" },
29-
{ text: "Act as if what you do makes a difference. It does.", author: "William James" },
30-
{ text: "Success is not in what you have, but who you are.", author: "Bo Bennett" },
31-
{ text: "Success is not final, failure is not fatal: It is the courage to continue that counts.", author: "Winston Churchill" },
32-
{ text: "The only person you are destined to become is the person you decide to be.", author: "Ralph Waldo Emerson" },
33-
{ text: "Don’t watch the clock; do what it does. Keep going.", author: "Sam Levenson" },
34-
{ text: "The only place where success comes before work is in the dictionary.", author: "Vidal Sassoon" },
35-
{ text: "Believe in yourself and all that you are. Know that there is something inside you that is greater than any obstacle.", author: "Christian D. Larson" },
36-
{ text: "Don’t be afraid to give up the good to go for the great.", author: "John D. Rockefeller" },
37-
{ text: "You are never too old to set another goal or to dream a new dream.", author: "C.S. Lewis" },
38-
{ text: "The mind is everything. What you think you become.", author: "Buddha" },
39-
{ text: "Life is short, and it is up to you to make it sweet.", author: "Sarah Louise Delany" },
40-
{ text: "The best way to find yourself is to lose yourself in the service of others.", author: "Mahatma Gandhi" },
41-
{ text: "To live a creative life, we must lose our fear of being wrong.", author: "Joseph Chilton Pearce" },
42-
{ text: "In order to succeed, we must first believe that we can.", author: "Nikos Kazantzakis" },
43-
{ text: "You have within you right now, everything you need to deal with whatever the world can throw at you.", author: "Brian Tracy" },
44-
{ text: "The only way to achieve the impossible is to believe it is possible.", author: "Charles Kingsleigh" },
45-
{ text: "Start where you are. Use what you have. Do what you can.", author: "Arthur Ashe" },
46-
{ text: "You are not your resume, you are your work.", author: "Seth Godin" },
47-
{ text: "Do what you love, love what you do.", author: "Wayne W. Dyer" },
48-
{ text: "Success is walking from failure to failure with no loss of enthusiasm.", author: "Winston Churchill" },
49-
{ text: "The only way to make sense out of change is to plunge into it, move with it, and join the dance.", author: "Alan Watts" },
50-
{ text: "The best way out is always through.", author: "Robert Frost" },
51-
{ text: "It is never too late to be what you might have been.", author: "George Eliot" },
52-
{ text: "The only limit to our realization of tomorrow is our doubts of today.", author: "Franklin D. Roosevelt" },
53-
{ text: "The best revenge is massive success.", author: "Frank Sinatra" },
54-
{ text: "Don't watch the clock; do what it does. Keep going.", author: "Sam Levenson" },
55-
{ text: "Life is what happens when you're busy making other plans.", author: "John Lennon" },
56-
{ text: "The best way to predict the future is to create it.", author: "Peter Drucker" },
57-
{ text: "You miss 100% of the shots you don't take.", author: "Wayne Gretzky" },
58-
{ text: "Do what you can, with what you have, where you are.", author: "Theodore Roosevelt" },
59-
{ text: "Act as if what you do makes a difference. It does.", author: "William James" },
60-
{ text: "The only person you are destined to become is the person you decide to be.", author: "Ralph Waldo Emerson" },
61-
{ text: "The only way to do great work is to love what you do.", author: "Steve Jobs" },
62-
{ text: "You are never too old to set another goal or to dream a new dream.", author: "C.S. Lewis" },
63-
{ text: "Believe in yourself and all that you are. Know that there is something inside you that is greater than any obstacle.", author: "Christian D. Larson" },
64-
{ text: "The future belongs to those who believe in the beauty of their dreams.", author: "Eleanor Roosevelt" },
65-
{ text: "Success is not in what you have, but who you are.", author: "Bo Bennett" },
66-
{ text: "Success usually comes to those who are too busy to be looking for it.", author: "Henry David Thoreau" },
67-
{ text: "You can never cross the ocean until you have the courage to lose sight of the shore.", author: "Christopher Columbus" },
68-
{ text: "The only limit to our realization of tomorrow is our doubts of today.", author: "Franklin D. Roosevelt" },
69-
{ text: "Opportunities don't happen. You create them.", author: "Chris Grosser" },
70-
{ text: "Do not wait to strike till the iron is hot, but make it hot by striking.", author: "William Butler Yeats" },
71-
{ text: "The only impossible journey is the one you never begin.", author: "Tony Robbins" },
72-
{ text: "You do not find the happy life. You make it.", author: "Camilla E. Kimball" },
73-
{ text: "Success is not final, failure is not fatal: It is the courage to continue that counts.", author: "Winston Churchill" },
74-
{ text: "The only way to achieve the impossible is to believe it is possible.", author: "Charles Kingsleigh" },
75-
{ text: "Start where you are. Use what you have. Do what you can.", author: "Arthur Ashe" },
76-
{ text: "You are not your resume, you are your work.", author: "Seth Godin" },
77-
{ text: "Do what you love, love what you do.", author: "Wayne W. Dyer" }
78-
]
3+
quotes = YAML.load_file(Rails.root.join('config', 'quotes.yml'))
4+
locale = I18n.locale.to_s
795

80-
# Use the current date to select a quote, ensuring it changes daily
81-
quotes[Date.today.yday % quotes.length]
6+
return nil unless quotes[locale] && quotes[locale]['quotes'].any?
7+
8+
date = Date.today.to_s
9+
quotes_for_locale = quotes[locale]['quotes']
10+
11+
# Use the date as a seed for the random number generator
12+
srand(date.hash)
13+
14+
# Select a quote based on the seeded random number
15+
quotes_for_locale.sample
8216
end
83-
8417
end

app/views/comments/_comment.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div class="comment-<%= comment.id %> container"
22
style="border: 1px solid black; padding: 1em; margin: 1em;">
33
<%= comment.user.email %><br />
4-
<span>Posted <%= time_ago_in_words(comment.created_at) %></span>
4+
<span><%= t('comments.posted', time_ago: time_ago_in_words(comment.created_at)) %></span>
55
<% if current_user == comment.user %>
66
<div class="button-group float-end">
7-
<%= button_to "Delete", [post, comment], class:"btn btn-danger", method: :delete %>
7+
<%= button_to t('comments.delete_button'), [post, comment], class: "btn btn-danger", method: :delete %>
88
</div>
99
<% end %>
1010
<hr />

app/views/comments/_form.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<%= form_with(model: [post, post.comments.build]) do |f| %>
22
<div class = "form-control">
33
<%= f.rich_text_area :body %>
4-
<%= f.submit "Reply", class: "btn btn-primary mt-1" %>
4+
<%= f.submit t('replies.submit'), class: "btn btn-primary mt-1" %>
55
</div>
66
<% end %>
+9-9
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
<div class="card" style="max-width: 600px; margin: auto; margin-top: 50px; border-radius: 0.5rem; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); width: 50%">
22
<div class="card-body" style="padding: 2rem;">
3-
<h5 class="card-title">Sign Up</h5>
3+
<h5 class="card-title"><%= t('registrations.new.title') %></h5>
44

55
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
66
<%= render "devise/shared/error_messages", resource: resource %>
77

88
<div class="mb-4">
9-
<%= f.label :email, class: 'form-label' %>
9+
<%= f.label :email, t('registrations.new.email'), class: 'form-label' %>
1010
<%= f.email_field :email, autofocus: true, autocomplete: "email", class: "form-control", id: 'exampleInputEmail1' %>
1111
</div>
1212

1313
<div class="mb-4">
14-
<%= f.label :name, class: 'form-label' %>
14+
<%= f.label :name, t('registrations.new.name'), class: 'form-label' %>
1515
<%= f.text_field :name, autofocus: true, autocomplete: "name", class: "form-control", id: 'exampleInputName' %>
1616
</div>
1717

1818
<div class="mb-4">
19-
<%= f.label :password, class: 'form-label' %>
20-
<%= f.password_field :password, autocomplete: "new-password", class: "form-control", id: 'exampleInputPassword1', placeholder: "Password: 8 characters minimum" %>
19+
<%= f.label :password, t('registrations.new.password'), class: 'form-label' %>
20+
<%= f.password_field :password, autocomplete: "new-password", class: "form-control", id: 'exampleInputPassword1', placeholder: t('registrations.new.password_placeholder') %>
2121
</div>
2222

2323
<div class="mb-4">
24-
<%= f.label :password_confirmation, class: 'form-label' %>
25-
<%= f.password_field :password_confirmation, autocomplete: "new-password", class: "form-control", id: 'exampleInputPasswordConfirmation', placeholder: "Confirm Password" %>
24+
<%= f.label :password_confirmation, t('registrations.new.password_confirmation'), class: 'form-label' %>
25+
<%= f.password_field :password_confirmation, autocomplete: "new-password", class: "form-control", id: 'exampleInputPasswordConfirmation', placeholder: t('registrations.new.password_confirmation_placeholder') %>
2626
</div>
2727

2828
<div class="mb-4">
29-
<%= f.submit "Sign up", class: "btn btn-primary w-100" %>
29+
<%= f.submit t('registrations.new.submit'), class: "btn btn-primary w-100" %>
3030
</div>
3131
<% end %>
3232

3333
<p class="mt-3">
34-
<%= link_to 'Sign in', new_session_path(resource_name), class: 'text-primary' %>
34+
<%= link_to t('registrations.new.sign_in'), new_session_path(resource_name), class: 'text-primary' %>
3535
</p>
3636
</div>
3737
</div>

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
<div class="card" style="max-width: 600px; margin: auto; margin-top: 50px; border-radius: 0.5rem; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); width: 50%;">
22
<div class="card-body" style="padding: 2rem;">
3-
<h5 class="card-title">Sign in to your account</h5>
3+
<h5 class="card-title"><%= t('sessions.sign_in.title') %></h5>
44

55
<%= form_with(url: session_path(resource_name), scope: :user, local: true) do |f| %>
66
<div class="mb-4">
7-
<%= f.label :email, class: 'form-label' %>
7+
<%= f.label :email, t('sessions.sign_in.email'), class: 'form-label' %>
88
<%= f.email_field :email, class: 'form-control', id: 'exampleInputEmail1' %>
99
</div>
1010

1111
<div class="mb-4">
12-
<%= f.label :password, class: 'form-label' %>
12+
<%= f.label :password, t('sessions.sign_in.password'), class: 'form-label' %>
1313
<%= f.password_field :password, class: 'form-control', id: 'exampleInputPassword1' %>
1414
</div>
1515

1616
<div class="mb-4 form-check">
1717
<%= f.check_box :remember_me, class: 'form-check-input', id: 'exampleCheck1' %>
18-
<%= f.label :remember_me, class: 'form-check-label', for: 'exampleCheck1' %>
18+
<%= f.label :remember_me, t('sessions.sign_in.remember_me'), class: 'form-check-label', for: 'exampleCheck1' %>
1919
</div>
2020

21-
<button type="submit" class="btn btn-primary w-100">Sign in</button>
21+
<button type="submit" class="btn btn-primary w-100"><%= t('sessions.sign_in.title') %></button>
2222

2323
<p class="mt-3">
24-
<%= link_to 'Forgot your password?', new_password_path(resource_name), class: 'text-primary' %>
24+
<%= link_to t('sessions.sign_in.forgot_password'), new_password_path(resource_name), class: 'text-primary' %>
2525
</p>
2626
<p class="mt-3">
27-
<%= link_to 'Sign up', new_registration_path(resource_name), class: 'text-primary' %>
27+
<%= link_to t('sessions.sign_in.sign_up'), new_registration_path(resource_name), class: 'text-primary' %>
2828
</p>
2929
<% end %>
3030
</div>

app/views/layouts/_navbar.html.erb

+27-21
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,56 @@
1-
<!-- app/views/layouts/_navbar.html.erb -->
21
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
32
<div class="container-fluid">
4-
<%= link_to 'Rails Blog', root_path, class: 'navbar-brand' %>
5-
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
3+
<%= link_to t('navbar.title'), root_path, class: 'navbar-brand' %>
4+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="<%= t('navbar.toggle_label') %>">
65
<span class="navbar-toggler-icon"></span>
76
</button>
87
<div class="collapse navbar-collapse" id="navbarSupportedContent">
98
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
109
<li class="nav-item">
11-
<%= link_to 'Blog', your_posts_path, class: 'nav-link' %>
10+
<%= link_to t('navbar.blog'), your_posts_path, class: 'nav-link' %>
1211
</li>
1312
<li class="nav-item">
14-
<%= link_to 'About', about_path, class: 'nav-link' %>
13+
<%= link_to t('navbar.about'), about_path, class: 'nav-link' %>
1514
</li>
1615
<li class="nav-item dropdown">
1716
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
18-
Post
17+
<%= t('navbar.post') %>
1918
</a>
2019
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
21-
<li><%= link_to 'New Post', new_post_path, class: 'dropdown-item' %></li>
22-
20+
<li><%= link_to t('navbar.new_post'), new_post_path, class: 'dropdown-item' %></li>
2321
</ul>
2422
</li>
2523
<% if user_signed_in? %>
2624
<li class="nav-item dropdown">
27-
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
25+
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownUser" role="button" data-bs-toggle="dropdown" aria-expanded="false">
2826
<%= current_user.name %>
2927
</a>
30-
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
31-
<%= link_to "Profile", user_path(current_user), class: 'dropdown-item' %>
32-
<%= link_to "Sign out", destroy_user_session_path, class: 'dropdown-item' %></li>
33-
<%= link_to "Edit User", edit_user_registration_path, class: 'dropdown-item' %></li>
28+
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownUser">
29+
<li><%= link_to t('navbar.profile'), user_path(current_user), class: 'dropdown-item' %></li>
30+
<li><%= link_to t('navbar.edit_user'), edit_user_registration_path, class: 'dropdown-item' %></li>
31+
<li><%= link_to t('navbar.sign_out'), destroy_user_session_path, class: 'dropdown-item' %></li>
3432
</ul>
3533
</li>
36-
37-
<%else %>
34+
<% else %>
3835
<li class="nav-item dropdown">
39-
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
40-
Log in
36+
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownLogin" role="button" data-bs-toggle="dropdown" aria-expanded="false">
37+
<%= t('navbar.log_in') %>
4138
</a>
42-
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
43-
<li><%= link_to 'Log In or Sign Up', new_user_session_path, class: 'dropdown-item' %></li>
39+
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownLogin">
40+
<li><%= link_to t('navbar.log_in_or_sign_up'), new_user_session_path, class: 'dropdown-item' %></li>
4441
</ul>
4542
</li>
46-
<%end %>
43+
<% end %>
44+
<li class="nav-item dropdown">
45+
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownLanguage" role="button" data-bs-toggle="dropdown" aria-expanded="false">
46+
<%= t('navbar.language') %>
47+
</a>
48+
<ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownLanguage">
49+
<li><%= link_to t('navbar.language_english'), url_for(locale: 'en'), class: 'dropdown-item' %></li>
50+
<li><%= link_to t('navbar.language_japanese'), url_for(locale: 'jp'), class: 'dropdown-item' %></li>
51+
</ul>
52+
</li>
4753
</ul>
4854
</div>
4955
</div>
50-
</nav>
56+
</nav>

0 commit comments

Comments
 (0)