Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where locale is not read from session #1878

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Unreleased
- Fix managed install path for SPIN environments [#1877](https://github.com/Shopify/shopify_app/pull/1877)
- Migrate fullpage redirect to App Bridge CDN [#1870](https://github.com/Shopify/shopify_app/pull/1870)
- Improve embedded requests detection with `Sec-Fetch-Dest` header [#1873](https://github.com/Shopify/shopify_app/pull/1873)
- Fix bug where locale is not read from session if locale param is not present in app request [#1878](https://github.com/Shopify/shopify_app/pull/1878)

22.2.1 (May 6,2024)
----------
Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_app/controller_concerns/localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Localization
private

def set_locale(&action)
locale = params[:locale] || I18n.default_locale
locale = params[:locale] || session[:locale] || I18n.default_locale

# Fallback to the 2 letter language code if the requested locale unavailable
unless I18n.available_locales.include?(locale.to_sym)
Expand Down
14 changes: 13 additions & 1 deletion test/shopify_app/controller_concerns/localization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@ class LocalizationTest < ActionController::TestCase
I18n.available_locales = [:en, :de, :es, :ja, :fr]
end

test "falls back to I18n.default if locale param is not present" do
test "falls back to locale stored in session if locale param is not present" do
I18n.default_locale = :ja

with_test_routes do
@request.session[:locale] = :de

get :index
assert_equal :de, response.body.to_sym
end
end

test "falls back to I18n.default if locale param is not present and session not populated" do
I18n.default_locale = :ja

with_test_routes do
@request.session[:locale] = nil
get :index
assert_equal :ja, response.body.to_sym
end
Expand Down
Loading