Skip to content

Instantly share code, notes, and snippets.

@sonsongithub
Created July 2, 2013 01:25
Show Gist options
  • Save sonsongithub/5906124 to your computer and use it in GitHub Desktop.
Save sonsongithub/5906124 to your computer and use it in GitHub Desktop.
Merge script for .strings file generated from Storyboard. ibtool often fails to merge importing .strings file into new generated one.
#!/usr/bin/ruby
require 'optparse'
def main
argv = {}
OptionParser.new do |opt|
opt.on('--previous VALUE') do |v|
argv[:previous] = v
end
opt.on('--current VALUE') do |v|
argv[:current] = v
end
opt.parse!(ARGV)
end
if !argv[:previous] || !argv[:current]
return
end
text = File::open(argv[:previous], "r").read
output = File::open(argv[:current], "r").read
dictionary = {}
text.scan(/^\"([A-Za-z0-9\-\.]+)\" = \"(.+)\";$/).each{|result|
dictionary[result[0]] = result[1]
}
output.each_line{|line|
if line =~ /^\"([A-Za-z0-9\-\.]+)\" = \"(.+)\";$/
if dictionary[$1] && dictionary[$1] != $2
puts sprintf("\"%s\" = \"%s\";", $1, dictionary[$1])
next
end
end
puts line
}
end
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment