Skip to content

Commit

Permalink
Internationalize/I18n the Dashboard Engine
Browse files Browse the repository at this point in the history
@bensheldon, I had a little bit of progress, so I would like to share it with you
  • Loading branch information
Juan Vasquez committed Jan 26, 2022
1 parent 6f0a3fa commit fbe0144
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion engine/app/controllers/good_job/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class BaseController < ActionController::Base # rubocop:disable Rails/Applicatio
private

def switch_locale(&action)
I18n.with_locale(:en, &action)
locale = params[:locale] || I18n.default_locale
I18n.with_locale(locale, &action)
end
end
end
2 changes: 1 addition & 1 deletion engine/app/views/layouts/good_job/base.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<%= link_to "GoodJob 👍", root_path, class: 'navbar-brand mb-0 h1' %>
<%= link_to t("app_name"), root_path, class: 'navbar-brand mb-0 h1' %>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
Expand Down
2 changes: 2 additions & 0 deletions engine/config/locales/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en:
app_name: "GoodJob 👍"
2 changes: 2 additions & 0 deletions engine/config/locales/es.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
es:
app_name: "BuenTrabajo 👍"
8 changes: 8 additions & 0 deletions spec/system/dashboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,12 @@
end.to change { unfinished_job.head_execution(reload: true).finished_at }.to within(1.second).of(Time.current)
end
end

describe "I18n" do
it "renders good_job in Spanish", js: true do
I18n.default_locale = :es
visit "/good_job"
expect(page).to have_content "BuenTrabajo 👍"
end
end
end

0 comments on commit fbe0144

Please sign in to comment.