Skip to content

Commit

Permalink
Merge pull request #109 from jhawthorn/locales_all
Browse files Browse the repository at this point in the history
Improve Locale.all and all_locales_options
  • Loading branch information
kennyadsl authored Feb 15, 2018
2 parents 57fde48 + 0a4451e commit fbae1b8
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 12 deletions.
4 changes: 1 addition & 3 deletions app/helpers/solidus_i18n/locale_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/locales/en-IN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config/locales/es-MX.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions lib/solidus_i18n/locale.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
35 changes: 35 additions & 0 deletions spec/helpers/locale_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions spec/lib/solidus_i18n/locale_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fbae1b8

Please sign in to comment.