Created
July 2, 2013 01:25
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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