diff --git a/spec/integrity/i18n_spec.rb b/spec/integrity/i18n_spec.rb index e7b9c08fec9..5e95b706a72 100644 --- a/spec/integrity/i18n_spec.rb +++ b/spec/integrity/i18n_spec.rb @@ -58,7 +58,7 @@ describe "i18n integrity checks" do end end - describe 'keys in English locale files' do + describe 'English locale file' do locale_files = ['config/locales', 'plugins/**/locales'] .product(['server.en.yml', 'client.en.yml']) .collect { |dir, filename| Dir["#{Rails.root}/#{dir}/#{filename}"] } @@ -85,12 +85,42 @@ describe "i18n integrity checks" do end end + module Pluralizations + def self.load(path) + whitelist = Regexp.union([/messages.restrict_dependent_destroy/]) + + yaml = YAML.load_file("#{Rails.root}/#{path}") + pluralizations = find_pluralizations(yaml['en']) + pluralizations.reject! { |key| key.match(whitelist) } + pluralizations + end + + def self.find_pluralizations(hash, parent_key = '', pluralizations = Hash.new) + hash.each do |key, value| + if value.is_a? Hash + current_key = parent_key.blank? ? key : "#{parent_key}.#{key}" + find_pluralizations(value, current_key, pluralizations) + elsif key == 'one' || key == 'other' + pluralizations[parent_key] = hash + end + end + + pluralizations + end + end + locale_files.each do |path| context path do it 'has no duplicate keys' do duplicates = DuplicateKeyFinder.new.find_duplicates("#{Rails.root}/#{path}") expect(duplicates).to be_empty end + + Pluralizations.load(path).each do |key, values| + it "key '#{key}' has valid pluralizations" do + expect(values.keys).to contain_exactly('one', 'other') + end + end end end end