Skip to content

Commit

Permalink
Merge branch 'kaigionrails' into kaigionrails2024
Browse files Browse the repository at this point in the history
  • Loading branch information
unasuke committed Jun 17, 2024
2 parents 2c68a0f + 3613e7f commit b3b74ef
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 1 deletion.
10 changes: 10 additions & 0 deletions app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ProposalsController < ApplicationController
before_action :require_proposal, except: [ :index, :create, :new, :parse_edit_field ]
before_action :require_invite_or_speaker, only: [:show]
before_action :require_speaker, except: [ :index, :create, :new, :parse_edit_field ]
around_action :set_locale

decorates_assigned :proposal

Expand Down Expand Up @@ -37,6 +38,8 @@ def finalized_notification
end

def new
@switch_locale_path = new_event_proposal_path(@event, locale: (I18n.locale == :ja ? :en : :ja))

if @event.closed?
redirect_to event_path (@event)
flash[:danger] = "The CFP is closed for proposal submissions."
Expand Down Expand Up @@ -192,4 +195,11 @@ def incomplete_profile_msg
msg.html_safe
end
end

def set_locale(&action)
locale = params[:locale] || session[:locale]
locale = I18n.default_locale unless I18n.available_locales.include?(locale&.to_sym)
session[:locale] = locale
I18n.with_locale(locale, &action)
end
end
6 changes: 5 additions & 1 deletion app/views/proposals/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.event-info-bar
.row
.row.margin-bottom
.col-md-8
.event-info.event-info-dense
%strong.event-title= event.name
Expand All @@ -16,6 +16,10 @@
%span.event-meta
= t("proposal.new.closes")
%strong= l(event.closes_at, format: :short)
.row
.col-md-4.col-md-push-8.text-right.test-right-responsive
%a{class: "btn btn-default", href: @switch_locale_path}
= t("proposal.new.change_locale")
.page-header.page-header-slim
.row
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ en:
hello: "Hello world"
proposal:
new:
change_locale: "日本語に切り替える"
title: "Submit a Proposal"
closes: "CFP closes:"
form: "Proposal Form"
Expand Down
1 change: 1 addition & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ja:
hello: こんにちは
proposal:
new:
change_locale: "Switch to en locale"
title: "プロポーザルを提出する"
closes: 締め切り
form: フォーム
Expand Down
33 changes: 33 additions & 0 deletions spec/features/proposal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,39 @@
expect(page).to have_text("The CFP is closed for proposal submissions.")
end
end

context "with locale param" do
context "when locale is 'en'" do
it "shows the page in en locale" do
visit new_event_proposal_path(event_slug: event.slug, locale: 'en')
expect(page).to have_text("Submit a Proposal")
end
end

context "when locale is 'ja'" do
it "shows the page in ja locale" do
visit new_event_proposal_path(event_slug: event.slug, locale: 'ja')
expect(page).to have_text("プロポーザルを提出する")
end
end

context "when unknown locale" do
it "shows the page in en locale (as fallback)" do
#FIXME: for test, fallback to en locale, but production fallback to ja locale
visit new_event_proposal_path(event_slug: event.slug, locale: 'xx')
expect(page).to have_text("Submit a Proposal")
end
end
end

context "when click locale switch button" do
it "switches the locale" do
go_to_new_proposal
expect(page).to have_text("日本語に切り替える")
click_on '日本語に切り替える'
expect(page).to have_text("Switch to en locale")
end
end
end

context "when submitting", js: true do
Expand Down

0 comments on commit b3b74ef

Please sign in to comment.