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 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/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/helpers/locale_helper_spec.rb b/spec/helpers/locale_helper_spec.rb new file mode 100644 index 00000000..c1ac5840 --- /dev/null +++ b/spec/helpers/locale_helper_spec.rb @@ -0,0 +1,35 @@ +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 + + 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 diff --git a/spec/lib/solidus_i18n/locale_spec.rb b/spec/lib/solidus_i18n/locale_spec.rb new file mode 100644 index 00000000..87a71e51 --- /dev/null +++ b/spec/lib/solidus_i18n/locale_spec.rb @@ -0,0 +1,53 @@ +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[ + en + 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