lib/yaml-validator.rb in yaml-validator-0.1.1 vs lib/yaml-validator.rb in yaml-validator-0.1.2

- old
+ new

@@ -1,8 +1,9 @@ require 'yaml' require 'yaml-validator/version' require_relative './helpers' +require_relative './pluralization-validator' class YamlValidator def initialize(root_path, options = {}) @options = options @@ -52,10 +53,11 @@ yaml_object = yaml_object[yaml_object.keys[0]] yaml_object = Helpers.normalize_yaml(yaml_object) errors += validate_yaml_object('', yaml_object) if @options[:show_missing] errors.concat find_missing_translations(yaml_object) + errors.concat find_missing_pluralizations(filename, yaml_object) end errors.map { |err| "#{filename}: #{err}" } end @@ -71,15 +73,16 @@ end def validate_yaml_object(full_key, yaml_object) return [] if yaml_object.nil? errors = [] + is_pluralization = Helpers.pluralization? yaml_object yaml_object.each do |key, value| full_subkey = (full_key.empty?) ? key : "#{full_key}.#{key}" if value.is_a? String - errors.concat validate_item(full_subkey, value) + errors.concat validate_item(full_subkey, value, is_pluralization) else errors.concat validate_yaml_object(full_subkey, value) end end errors @@ -103,10 +106,15 @@ errors.concat find_missing_translations_in_en_object(full_subkey, value, yaml_object) end end errors end + + def find_missing_pluralizations(filename, yaml_object) + language = File.basename(filename, '.*') + PluralizationValidator.validate(language, yaml_object) + end def self.find_key_in_yaml_object(full_key, yaml_object) position = yaml_object full_key.split('.').each do |key| return nil unless position.is_a? Hash @@ -118,13 +126,17 @@ else nil end end - def validate_item(full_key, value) + def validate_item(full_key, value, is_pluralization = false) real_vars = get_key_en_vars(full_key) if real_vars.nil? - return ["#{full_key} doesn't exist in en.yml"] + if is_pluralization + return [] + else + return ["#{full_key} doesn't exist in en.yml"] + end end used_vars = identify_variables(value) errors = []