Remove untranslated strings on import

pull/25/head
Alex Baker 11 years ago
parent ce40a07d65
commit 943544f8bf

@ -0,0 +1,53 @@
require 'rexml/document'
STRINGS = {}
def load(path)
file = File.new(path)
doc = REXML::Document.new(file)
doc.context[:attribute_quote] = :quote
doc
end
def index_elements(doc)
doc.elements['resources'].each_element('string') do |elem|
string_name = elem.attributes['name']
raise "duplicate string" if STRINGS.has_key? string_name
STRINGS[string_name] = elem.text
end
end
def clean(path)
doc = load(path)
to_remove = []
doc.elements['resources'].each_element('string') do |elem|
string_name = elem.attributes['name']
to_remove << string_name if elem.text.eql? STRINGS[string_name]
end
to_remove.each do |name|
doc.elements.delete("resources/string[@name='#{name}']")
end
File.open(path, 'w') do |f|
head, *tail = doc.to_s.split("\n").reject { |x| x.strip.eql? ""}
f.puts head
f.puts "<!-- ************************************************************** -->"
f.puts "<!-- ********* THIS FILE IS GENERATED BY GETLOCALIZATION ********** -->"
f.puts "<!-- ******** http://www.getlocalization.com/tasks_android ******** -->"
f.puts "<!-- ******************* DO NOT MODIFY MANUALLY ******************* -->"
f.puts "<!-- ************************************************************** -->"
f.print tail.join("\n")
end
end
def remove_untranslated_strings(*string_files)
index_elements(load("api/src/main/res/values/strings.xml"))
Dir.glob("astrid/src/main/res/values/strings*.xml").each do |path|
index_elements(load(path))
end
string_files.each { |path| clean path }
end
if __FILE__ == $0
lang = ARGV[0]
remove_untranslated_strings("../api/src/main/res/values-#{lang}/strings.xml", "../astrid/src/main/res/values-#{lang}/strings.xml")
end

@ -1,4 +1,7 @@
#!/usr/bin/env ruby
$:.unshift File.dirname(__FILE__)
require 'clean_translations'
# Script for invoking the GetLocalization tools
# IMPORTANT: Right now, must be invoked from the project's root directory.
# Usage: ./bin/getloc.rb [cmd] [lang]
@ -89,6 +92,7 @@ def import(tmp_files, lang, dst_files_block)
puts "Moving #{tmp_files[i]} to #{dst_files[i]}"
%x(mv #{tmp_files[i]} #{dst_files[i]})
end
remove_untranslated_strings *dst_files
end
end

Loading…
Cancel
Save