Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Added LocaleHelper#should_render_locale_dropdown?

Damian Legawiec79c8e88b616d
diff --git a/core/app/helpers/spree/locale_helper.rb b/core/app/helpers/spree/locale_helper.rb
index 7f3e083470..9a5da9089a 100644
--- a/core/app/helpers/spree/locale_helper.rb
+++ b/core/app/helpers/spree/locale_helper.rb
@@ -21,5 +21,11 @@ module Spree
locale.to_s == 'en' ? ['English (US)', 'en'] : [locale, locale.to_s]
end
end
+
+ def should_render_locale_dropdown?
+ return false if current_store.nil?
+
+ current_store.supported_locales_list.size > 1
+ end
end
end
diff --git a/core/spec/helpers/locale_helper_spec.rb b/core/spec/helpers/locale_helper_spec.rb
index d3d5ad7247..2fdea10924 100644
--- a/core/spec/helpers/locale_helper_spec.rb
+++ b/core/spec/helpers/locale_helper_spec.rb
@@ -43,4 +43,18 @@ describe Spree::LocaleHelper, type: :helper do
describe '#locale_presentation' do
it { expect(locale_presentation(:fr)).to eq( ['Français (FR)', 'fr']) }
end
+
+ describe '#should_render_locale_dropdown?' do
+ context 'store with multiple locales' do
+ let(:current_store) { eu_store }
+
+ it { expect(should_render_locale_dropdown?).to be_truthy }
+ end
+
+ context 'store with single locale' do
+ let(:current_store) { create(:store, supported_locales: 'en', default_locale: 'en') }
+
+ it { expect(should_render_locale_dropdown?).to be_falsey }
+ end
+ end
end