Skip to content

Instantly share code, notes, and snippets.

@kueda
Created May 19, 2014 21:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kueda/a0742d08ae5bcc03637e to your computer and use it in GitHub Desktop.
Save kueda/a0742d08ae5bcc03637e to your computer and use it in GitHub Desktop.
Spit out text from a .xib or .storyboard file as it appears in xcode. Useful for diffing and working with translations.
#!/usr/bin/env ruby
require 'rubygems'
require 'trollop'
require 'nokogiri'
require 'tmpdir'
opts = Trollop::options do
banner <<-EOS
Spit out text from a .xib or .storyboard file as it appears in xcode. Useful
for diffing and working with translations.
Usage:
ruby xibstrings.rb path/to/file.storyboard
Dependencies:
* Ruby
* Rubygems
* Trollop
* Nokogiri
where [options] are:
EOS
opt :debug, "Print debug statements", :type => :boolean, :short => "-d"
end
OPTS = opts
def run(cmd)
puts "* Running #{cmd}" if OPTS[:debug]
system cmd
end
basename = "storyboardstrings-#{Time.now.to_i}"
binary_plist_path = File.join(Dir::tmpdir, "#{basename}.strings")
xml_plist_path = File.join(Dir::tmpdir, "#{basename}.xml")
xib_path = ARGV[0]
run "ibtool #{xib_path} --generate-strings #{binary_plist_path}"
run "plutil -convert xml1 -o - #{binary_plist_path} > #{xml_plist_path}"
doc = Nokogiri::XML(File.open(xml_plist_path))
if OPTS[:debug]
puts "* Generated plist"
end
doc.search('//key').each do |key|
puts "\"#{key.text}\" = \"#{key.next_element.text}\";"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment