lib/apstrings/strings_validator.rb in apstrings-0.2.1 vs lib/apstrings/strings_validator.rb in apstrings-0.2.2
- old
+ new
@@ -4,13 +4,16 @@
require 'apstrings/logger'
class Validator
def self.validate(file,masterFile)
+ @master = nil
puts "apstrings: start validate strings file ..."
if nil == masterFile
Log::warn("No master file provided, validating file format for #{file} only ...")
+ else
+ @master = Validator::paredFile(masterFile)
end
valid_master, valid_file , no_missing_key = true,true,true
valid_file = Validator::validate_format(file)
@@ -80,13 +83,14 @@
sf = Validator::paredFile(file)
variables_regex = /%[hlqLztj]?[@%dDuUxXoOfeEgGcCsSpaAF]/
mismatchs = []
sf.key_values.each {
|e| e.each_pair {
- |key,value|
+ |key,value|
+ fixed_key = Validator::value_in_master(key)
striped_value = value.gsub(/%\d\$/,'%') # Strip numbered format placeholders , e.g. %1$@ --> %@
- key_variables = key.scan(variables_regex)
+ key_variables = fixed_key.scan(variables_regex)
value_variables = striped_value.scan(variables_regex)
if !(key_variables.sort == value_variables.sort)
mismatchs << {key => value}
end
}
@@ -95,9 +99,22 @@
end
def self.paredFile(file)
file = Reader.read(file)
StringsParser.new(file).parse_file
+ end
+
+ def self.value_in_master(key)
+ if @master
+ value_comment = @master.to_hash[key] #
+ if value_comment == nil
+ return key
+ else
+ return value_comment.keys[0]
+ end
+ else
+ key
+ end
end
end
end