From 56173bab42dec4fae1c814c7d9f20c9411dac072 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 8 Feb 2018 16:54:04 -0800 Subject: [PATCH 1/5] Add spec against SolidusI18n::Locale.all --- spec/lib/solidus_i18n/locale_spec.rb | 52 ++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 spec/lib/solidus_i18n/locale_spec.rb diff --git a/spec/lib/solidus_i18n/locale_spec.rb b/spec/lib/solidus_i18n/locale_spec.rb new file mode 100644 index 00000000..adcab478 --- /dev/null +++ b/spec/lib/solidus_i18n/locale_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +RSpec.describe SolidusI18n::Locale do + describe '.all' do + subject { SolidusI18n::Locale.all } + + it "Contains all available Solidus locales" do + # Add to this list when adding/removing locales + expect(subject).to match_array %i[ + zh-CN + cs + zh-TW + it + nl + da + tr + id + ro + pt-BR + ja + es + fr + de + ru + uk + ko + pt + et + sk + pl + nb + fa + fi + en-NZ + en-IN + en-AU + bg + en-GB + de-CH + es-MX + es-CL + th + ca + vi + sv + es-EC + lv + sl-SI + ] + end + end +end From 0c386dbf2b76f8f93247a36312ff8a5dbf56b569 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 8 Feb 2018 16:54:25 -0800 Subject: [PATCH 2/5] Use I18n.available_locales in Locale.all Previously this used Dir[] inside the locales directory. This didn't allow for locales coming from different gems. For this reason it also didn't include :en. --- lib/solidus_i18n/locale.rb | 10 +++------- spec/lib/solidus_i18n/locale_spec.rb | 1 + 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/lib/solidus_i18n/locale.rb b/lib/solidus_i18n/locale.rb index fba2271c..a637fee5 100644 --- a/lib/solidus_i18n/locale.rb +++ b/lib/solidus_i18n/locale.rb @@ -1,12 +1,8 @@ module SolidusI18n class Locale - class << self - def all - Dir["#{dir}/*.yml"].map { |f| File.basename(f, '.yml').to_sym } - end - - def dir - File.join(File.dirname(__FILE__), '/../../config/locales') + def self.all + I18n.available_locales.select do |locale| + I18n.t(:spree, locale: locale, fallback: false, default: nil) end end end diff --git a/spec/lib/solidus_i18n/locale_spec.rb b/spec/lib/solidus_i18n/locale_spec.rb index adcab478..87a71e51 100644 --- a/spec/lib/solidus_i18n/locale_spec.rb +++ b/spec/lib/solidus_i18n/locale_spec.rb @@ -7,6 +7,7 @@ it "Contains all available Solidus locales" do # Add to this list when adding/removing locales expect(subject).to match_array %i[ + en zh-CN cs zh-TW From 4a839a3cf1c9abdb4fdedd16ccc6d84ff149c492 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 8 Feb 2018 17:19:46 -0800 Subject: [PATCH 3/5] Avoid duplicate :en locales in all_locales_options --- app/helpers/solidus_i18n/locale_helper.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/helpers/solidus_i18n/locale_helper.rb b/app/helpers/solidus_i18n/locale_helper.rb index f46c3810..5ca79847 100644 --- a/app/helpers/solidus_i18n/locale_helper.rb +++ b/app/helpers/solidus_i18n/locale_helper.rb @@ -12,10 +12,8 @@ def available_locales_options Config.available_locales.map { |locale| locale_presentation(locale) } end - # Need to manually add en to the array because the en.yml was moved from - # this project. solidusio/solidus now has those keys. def all_locales_options - SolidusI18n::Locale.all.map { |locale| locale_presentation(locale) }.push(['English (EN)', :en]) + SolidusI18n::Locale.all.map { |locale| locale_presentation(locale) } end private From ea9fa3fdef78e6e0c1d002149ea8de101bd91920 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 8 Feb 2018 17:20:12 -0800 Subject: [PATCH 4/5] Add specs for all_locales_options --- spec/helpers/locale_helper_spec.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 spec/helpers/locale_helper_spec.rb diff --git a/spec/helpers/locale_helper_spec.rb b/spec/helpers/locale_helper_spec.rb new file mode 100644 index 00000000..a9740318 --- /dev/null +++ b/spec/helpers/locale_helper_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +RSpec.describe SolidusI18n::LocaleHelper do + describe '#all_locales_options' do + subject { all_locales_options } + + it 'includes en' do + is_expected.to include(["English (US)", :en]) + end + + it 'includes ja' do + is_expected.to include(["日本語 (ja-JP)", :ja]) + end + + describe 'locales' do + subject { all_locales_options.map(&:last) } + + it 'includes each locale only once' do + is_expected.to match_array(subject.uniq) + end + + it 'should match Locale.all' do + is_expected.to match_array SolidusI18n::Locale.all + end + end + end +end From 0a4451effbc954ebd9b11c46969a7c2f5b4c34f7 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Thu, 8 Feb 2018 17:35:57 -0800 Subject: [PATCH 5/5] Ensure locales have unique names Previously, we listed both en-IN as "English (UK)" and es-MX as "Castellano (ES)". This commit adds a spec to ensure that the locales have a unique names and updates the two offending locales. --- config/locales/en-IN.yml | 2 +- config/locales/es-MX.yml | 2 +- spec/helpers/locale_helper_spec.rb | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config/locales/en-IN.yml b/config/locales/en-IN.yml index b981dafa..0111ef64 100644 --- a/config/locales/en-IN.yml +++ b/config/locales/en-IN.yml @@ -631,7 +631,7 @@ en-IN: available_locales: language: localization_settings: - this_file_language: English (UK) + this_file_language: English (IN) icon: Icon identifier: image: Image diff --git a/config/locales/es-MX.yml b/config/locales/es-MX.yml index 15b53829..982deaf1 100644 --- a/config/locales/es-MX.yml +++ b/config/locales/es-MX.yml @@ -636,7 +636,7 @@ es-MX: available_locales: Traduciones Disponibles language: Idioma localization_settings: Ajustes de traducciones - this_file_language: + this_file_language: Castellano (MX) icon: Icono identifier: image: Imagen diff --git a/spec/helpers/locale_helper_spec.rb b/spec/helpers/locale_helper_spec.rb index a9740318..c1ac5840 100644 --- a/spec/helpers/locale_helper_spec.rb +++ b/spec/helpers/locale_helper_spec.rb @@ -23,5 +23,13 @@ is_expected.to match_array SolidusI18n::Locale.all end end + + describe 'locale presentation' do + subject { all_locales_options.map(&:first) } + + it 'should all be unique' do + is_expected.to match_array(subject.uniq) + end + end end end