2010-09-18 05:28:03 -04:00
|
|
|
#!/usr/bin/ruby
|
|
|
|
# Yaaic - Yet Another Android IRC Client
|
|
|
|
#
|
|
|
|
# Copyright 2009-2010 Sebastian Kaspari
|
|
|
|
#
|
|
|
|
# This file is part of Yaaic.
|
|
|
|
#
|
|
|
|
# Yaaic is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Yaaic is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# TODO: Use a XML parser instead of reading lines
|
|
|
|
|
2010-11-07 02:37:16 -05:00
|
|
|
base_path = "#{File.dirname(__FILE__)}/../application/res/"
|
2010-09-23 06:16:04 -04:00
|
|
|
original_file = "#{base_path}values/strings.xml"
|
|
|
|
languages = []
|
2010-09-23 08:00:54 -04:00
|
|
|
items = {}
|
2010-09-23 06:16:04 -04:00
|
|
|
pattern = Regexp.new '<string name="([^"]+)">([^<]+)</string>'
|
|
|
|
lang_pattern = Regexp.new 'values-([a-zA-Z_-]+)'
|
2010-09-23 08:00:54 -04:00
|
|
|
show_keys = false
|
|
|
|
|
|
|
|
show_keys = true if ARGV.length == 1 && ARGV[0] == '--show-keys'
|
2010-09-18 05:28:03 -04:00
|
|
|
|
2010-09-23 06:16:04 -04:00
|
|
|
# Scan for languages
|
|
|
|
Dir.new(base_path).entries.each { |directory|
|
|
|
|
result = lang_pattern.match directory
|
|
|
|
if !result.nil? then
|
|
|
|
languages.push result[1]
|
|
|
|
end
|
|
|
|
}
|
2010-09-18 05:28:03 -04:00
|
|
|
|
2010-09-23 06:16:04 -04:00
|
|
|
puts "Found #{languages.length} language(s): #{languages.inspect}"
|
2010-09-18 05:28:03 -04:00
|
|
|
|
|
|
|
# Grab all keys from the original file
|
|
|
|
file = File.new(original_file, 'r')
|
|
|
|
while line = file.gets
|
|
|
|
result = pattern.match line
|
|
|
|
if !result.nil? then
|
2010-09-23 08:00:54 -04:00
|
|
|
items[result[1]] = result[2]
|
2010-09-18 05:28:03 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
file.close
|
|
|
|
|
|
|
|
puts "Found #{items.length} items in strings.xml"
|
2010-09-23 06:16:04 -04:00
|
|
|
puts
|
2010-09-18 05:28:03 -04:00
|
|
|
|
2010-09-23 06:16:04 -04:00
|
|
|
# Check all langauges files for keys
|
2010-09-23 08:00:54 -04:00
|
|
|
languages.each { |language|
|
|
|
|
keys = 0
|
|
|
|
check = items.clone
|
|
|
|
untranslated = {}
|
|
|
|
unused = {}
|
2010-09-23 06:16:04 -04:00
|
|
|
language_file = "#{base_path}values-#{language}/strings.xml"
|
2010-09-18 05:28:03 -04:00
|
|
|
|
2010-09-23 06:16:04 -04:00
|
|
|
file = File.new(language_file, 'r')
|
|
|
|
while line = file.gets
|
|
|
|
result = pattern.match line
|
|
|
|
if !result.nil? then
|
2010-09-23 08:00:54 -04:00
|
|
|
key = result[1]
|
|
|
|
value = result[2]
|
|
|
|
|
|
|
|
check.delete key
|
|
|
|
if items[key].nil? then
|
|
|
|
unused[key] = value
|
|
|
|
else
|
|
|
|
untranslated[key] = value if items[key] == value
|
|
|
|
end
|
|
|
|
keys += 1
|
2010-09-23 06:16:04 -04:00
|
|
|
end
|
2010-09-18 05:28:03 -04:00
|
|
|
end
|
|
|
|
|
2010-09-23 08:00:54 -04:00
|
|
|
translated = items.length - untranslated.length - check.length
|
|
|
|
translated_percent = sprintf('%.2f', 100.to_f / items.length.to_f * translated.to_f)
|
|
|
|
keys_percent = sprintf('%.2f', 100.to_f / items.length.to_f * keys.to_f)
|
|
|
|
|
|
|
|
puts "Language #{language}"
|
|
|
|
puts " * Keys: #{keys.to_s.rjust 5}/#{items.length.to_s.ljust 5} #{keys_percent.to_s.rjust 6}%"
|
|
|
|
puts " * Translated: #{translated.to_s.rjust 5}/#{items.length.to_s.ljust 5} #{translated_percent.to_s.rjust 6}%"
|
|
|
|
|
|
|
|
if show_keys then
|
|
|
|
if check.length > 0 then
|
|
|
|
puts " * Missing keys:"
|
|
|
|
check.each { |key,value| puts " * #{key}" }
|
|
|
|
end
|
|
|
|
|
|
|
|
if untranslated.length > 0 then
|
|
|
|
puts " * Untranslated keys:"
|
|
|
|
untranslated.each { |key,value| puts " * #{key}" }
|
|
|
|
end
|
2010-09-18 05:28:03 -04:00
|
|
|
|
2010-09-23 08:00:54 -04:00
|
|
|
if unused.length > 0 then
|
|
|
|
puts " * Unused keys:"
|
|
|
|
unused.each { |key,value| puts " * #{key}" } if unused.length > 0
|
|
|
|
end
|
2010-09-23 06:16:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
puts
|
|
|
|
}
|
2010-09-18 05:28:03 -04:00
|
|
|
|