mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-22 17:02:21 -05:00
check_language.rb: Scan for existing languages and check all
This commit is contained in:
parent
5df472fe11
commit
f10aa55d5d
@ -18,30 +18,26 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
# along with Yaaic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
# TODO: Maybe check all existing languages instead of using a paremter
|
|
||||||
# TODO: Use a XML parser instead of reading lines
|
# TODO: Use a XML parser instead of reading lines
|
||||||
|
|
||||||
if ARGV.length != 1 then
|
base_path = "#{File.dirname(__FILE__)}/../res/"
|
||||||
puts "Which language should be checked...?"
|
original_file = "#{base_path}values/strings.xml"
|
||||||
exit
|
languages = []
|
||||||
end
|
items = []
|
||||||
|
pattern = Regexp.new '<string name="([^"]+)">([^<]+)</string>'
|
||||||
|
lang_pattern = Regexp.new 'values-([a-zA-Z_-]+)'
|
||||||
|
|
||||||
base_path = File.dirname(__FILE__)
|
# Scan for languages
|
||||||
language = ARGV[0]
|
Dir.new(base_path).entries.each { |directory|
|
||||||
|
result = lang_pattern.match directory
|
||||||
|
if !result.nil? then
|
||||||
|
languages.push result[1]
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
original_file = "#{base_path}/../res/values/strings.xml"
|
puts "Found #{languages.length} language(s): #{languages.inspect}"
|
||||||
language_file = "#{base_path}/../res/values-#{language}/strings.xml"
|
|
||||||
|
|
||||||
if !File.exists? language_file then
|
|
||||||
puts "File does not exists: #{language_file}"
|
|
||||||
exit
|
|
||||||
end
|
|
||||||
|
|
||||||
# Grab all keys from the original file
|
# Grab all keys from the original file
|
||||||
items = []
|
|
||||||
|
|
||||||
pattern = Regexp.new '<string name="([^"]+)">([^<]+)</string>'
|
|
||||||
|
|
||||||
file = File.new(original_file, 'r')
|
file = File.new(original_file, 'r')
|
||||||
while line = file.gets
|
while line = file.gets
|
||||||
result = pattern.match line
|
result = pattern.match line
|
||||||
@ -52,24 +48,30 @@ end
|
|||||||
file.close
|
file.close
|
||||||
|
|
||||||
puts "Found #{items.length} items in strings.xml"
|
puts "Found #{items.length} items in strings.xml"
|
||||||
|
puts
|
||||||
|
|
||||||
puts "Checking #{language}"
|
# Check all langauges files for keys
|
||||||
check = items.clone
|
languages.each { |language|
|
||||||
|
check = items.clone
|
||||||
|
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]
|
check.delete result[1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
percent = 100 - (100.to_f / items.length.to_f * check.length.to_f)
|
percent = sprintf('%.2f', 100 - (100.to_f / items.length.to_f * check.length.to_f))
|
||||||
|
|
||||||
if check.length == 0 then
|
if check.length == 0 then
|
||||||
puts "Language #{language} is OK (Translated: #{percent}%)"
|
puts "Language #{language} is OK (Translated: #{percent}%)"
|
||||||
else
|
else
|
||||||
puts "Language #{language} has missing translations (Translated: #{percent}%)"
|
puts "Language #{language} has missing translations (Translated: #{percent}%)"
|
||||||
check.each { |key| puts " #{key}" }
|
check.each { |key| puts " #{key}" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
puts
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user