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

Use carmen to translate available_countries helper #2537

Merged
merged 3 commits into from
Feb 8, 2018
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
10 changes: 9 additions & 1 deletion core/app/helpers/spree/base_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'carmen'

module Spree
module BaseHelper
def link_to_cart(text = nil)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions core/lib/spree/core/controller_helpers/common.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'carmen'

module Spree
module Core
module ControllerHelpers
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions core/spec/helpers/base_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down