mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-12-01 13:22:20 -05:00
check_languages.rb: Check all languages and show statistics
This commit is contained in:
parent
d86e90d6e9
commit
01cedbab92
@ -23,9 +23,12 @@
|
|||||||
base_path = "#{File.dirname(__FILE__)}/../res/"
|
base_path = "#{File.dirname(__FILE__)}/../res/"
|
||||||
original_file = "#{base_path}values/strings.xml"
|
original_file = "#{base_path}values/strings.xml"
|
||||||
languages = []
|
languages = []
|
||||||
items = []
|
items = {}
|
||||||
pattern = Regexp.new '<string name="([^"]+)">([^<]+)</string>'
|
pattern = Regexp.new '<string name="([^"]+)">([^<]+)</string>'
|
||||||
lang_pattern = Regexp.new 'values-([a-zA-Z_-]+)'
|
lang_pattern = Regexp.new 'values-([a-zA-Z_-]+)'
|
||||||
|
show_keys = false
|
||||||
|
|
||||||
|
show_keys = true if ARGV.length == 1 && ARGV[0] == '--show-keys'
|
||||||
|
|
||||||
# Scan for languages
|
# Scan for languages
|
||||||
Dir.new(base_path).entries.each { |directory|
|
Dir.new(base_path).entries.each { |directory|
|
||||||
@ -42,7 +45,7 @@ file = File.new(original_file, 'r')
|
|||||||
while line = file.gets
|
while line = file.gets
|
||||||
result = pattern.match line
|
result = pattern.match line
|
||||||
if !result.nil? then
|
if !result.nil? then
|
||||||
items.push result[1]
|
items[result[1]] = result[2]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
file.close
|
file.close
|
||||||
@ -52,24 +55,52 @@ puts
|
|||||||
|
|
||||||
# Check all langauges files for keys
|
# Check all langauges files for keys
|
||||||
languages.each { |language|
|
languages.each { |language|
|
||||||
|
keys = 0
|
||||||
check = items.clone
|
check = items.clone
|
||||||
|
untranslated = {}
|
||||||
|
unused = {}
|
||||||
language_file = "#{base_path}values-#{language}/strings.xml"
|
language_file = "#{base_path}values-#{language}/strings.xml"
|
||||||
|
|
||||||
file = File.new(language_file, 'r')
|
file = File.new(language_file, 'r')
|
||||||
while line = file.gets
|
while line = file.gets
|
||||||
result = pattern.match line
|
result = pattern.match line
|
||||||
if !result.nil? then
|
if !result.nil? then
|
||||||
check.delete result[1]
|
key = result[1]
|
||||||
end
|
value = result[2]
|
||||||
end
|
|
||||||
|
|
||||||
percent = sprintf('%.2f', 100 - (100.to_f / items.length.to_f * check.length.to_f))
|
check.delete key
|
||||||
|
if items[key].nil? then
|
||||||
if check.length == 0 then
|
unused[key] = value
|
||||||
puts "Language #{language} is OK (Translated: #{percent}%)"
|
|
||||||
else
|
else
|
||||||
puts "Language #{language} has missing translations (Translated: #{percent}%)"
|
untranslated[key] = value if items[key] == value
|
||||||
check.each { |key| puts " #{key}" }
|
end
|
||||||
|
keys += 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
if unused.length > 0 then
|
||||||
|
puts " * Unused keys:"
|
||||||
|
unused.each { |key,value| puts " * #{key}" } if unused.length > 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
puts
|
puts
|
Loading…
Reference in New Issue
Block a user