You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tasks/bin/clean_translations.rb

53 lines
1.7 KiB
Ruby

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