diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb index 41777435c7e..d6ced9b15af 100644 --- a/core/app/helpers/spree/base_helper.rb +++ b/core/app/helpers/spree/base_helper.rb @@ -1,3 +1,5 @@ +require 'carmen' + module Spree module BaseHelper def link_to_cart(text = nil) @@ -113,8 +115,14 @@ def available_countries countries = Country.all end + country_names = Carmen::Country.all.map do |country| + [country.code, country.name] + end.to_h + + country_names.update I18n.t('spree.country_names', default: {}).stringify_keys + countries.collect do |country| - country.name = t(country.iso, scope: 'spree.country_names', default: country.name) + country.name = country_names.fetch(country.iso, country.name) country end.sort_by { |c| c.name.parameterize } end diff --git a/core/lib/spree/core/controller_helpers/common.rb b/core/lib/spree/core/controller_helpers/common.rb index a54ce8248d5..eede7ae27d0 100644 --- a/core/lib/spree/core/controller_helpers/common.rb +++ b/core/lib/spree/core/controller_helpers/common.rb @@ -1,3 +1,5 @@ +require 'carmen' + module Spree module Core module ControllerHelpers @@ -49,6 +51,7 @@ def set_user_language locale ||= Rails.application.config.i18n.default_locale locale ||= I18n.default_locale I18n.locale = locale + Carmen.i18n_backend.locale = locale end # Returns which layout to render. diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb index 0a9e1608669..d81f5488bfa 100644 --- a/core/spec/helpers/base_helper_spec.rb +++ b/core/spec/helpers/base_helper_spec.rb @@ -20,6 +20,10 @@ it "return complete list of countries" do expect(available_countries.count).to eq(Spree::Country.count) end + + it "uses locales for country names" do + expect(available_countries).to include(having_attributes(name: "United States of America")) + end end context "with a checkout zone defined" do