lib/yaml-validator.rb in yaml-validator-0.1.0 vs lib/yaml-validator.rb in yaml-validator-0.1.1
- old
+ new
@@ -45,20 +45,33 @@
yaml_object = YAML.load_file(filepath)
rescue Psych::SyntaxError => e
return [e.message.sub(/^\([^)]+\)/, filename)]
end
+ errors = validate_root_language(yaml_object, File.basename(filename))
+
yaml_object = yaml_object[yaml_object.keys[0]]
yaml_object = Helpers.normalize_yaml(yaml_object)
- errors = validate_yaml_object('', yaml_object)
+ errors += validate_yaml_object('', yaml_object)
if @options[:show_missing]
errors.concat find_missing_translations(yaml_object)
end
errors.map { |err| "#{filename}: #{err}" }
end
+ def validate_root_language(yaml_object, file_name)
+ errors = []
+
+ lang = yaml_object.keys.first
+ if lang != file_name.split(".").first
+ errors << "invalid root language (#{lang})"
+ end
+
+ errors
+ end
+
def validate_yaml_object(full_key, yaml_object)
return [] if yaml_object.nil?
errors = []
yaml_object.each do |key, value|
@@ -153,10 +166,10 @@
end
with_vars
end
def identify_variables(string)
- string.scan(/%{([^}]+)}/).map { |v| v[0] }
+ string.scan(/%\{([^}]+)\}/).map(&:first)
end
end