Skip to content

Instantly share code, notes, and snippets.

@yitsushi
Created May 17, 2012 19:05
Show Gist options
  • Save yitsushi/2720986 to your computer and use it in GitHub Desktop.
Save yitsushi/2720986 to your computer and use it in GitHub Desktop.
merge new file entries into the old translated strings.xml for android translators (doesn't override original files)
require 'rubygems'
require 'xmlsimple'
old_file = ARGV[0] rescue nil
new_file = ARGV[1] rescue nil
output = ARGV[2] rescue nil
if old_file.nil? or new_file.nil?
puts "#{$0} <old_string.xml> <new_string.xml> [output_string.xml]"
exit
end
old_data = XmlSimple.xml_in(old_file, { 'KeyAttr' => 'name', 'KeepRoot' => true })
new_data = XmlSimple.xml_in(new_file, { 'KeyAttr' => 'name', 'KeepRoot' => true })
new_data['resources'][0]['string'].each do |key, value|
next unless old_data['resources'][0]['string'][key].nil?
old_data['resources'][0]['string'][key] = value
end
#p new_data
doc = XmlSimple.xml_out(new_data, { 'KeyAttr' => 'name',
'KeepRoot' => true,
'Indent' => " ",
'XmlDeclaration' => '<?xml version="1.0" encoding="utf-8"?>',
'NoEscape' => true
})
if output.nil?
puts doc
else
File.open(output,'w') do |file|
file.puts doc
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment