From 14a76d2c95f87a41994b9993ca0d44be33ab6033 Mon Sep 17 00:00:00 2001 From: Sebastian Kaspari Date: Sat, 18 Sep 2010 11:28:03 +0200 Subject: [PATCH] check_language.rb script: check if there are untranslated strings in a specific language file --- res/values/strings.xml | 4 ++- tools/check_language.rb | 76 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100755 tools/check_language.rb diff --git a/res/values/strings.xml b/res/values/strings.xml index 5b7f8b1..18d75c7 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -160,7 +160,9 @@ Show icons Show icons to highlight special events Show colors - Show colors to highlight special eventsColorize nicknamesShow nicknames in different colors + Show colors to highlight special events + Colorize nicknames + Show nicknames in different colors Show timestamp Prefix all messages with a timestamp 24 hour format diff --git a/tools/check_language.rb b/tools/check_language.rb new file mode 100755 index 0000000..01986b1 --- /dev/null +++ b/tools/check_language.rb @@ -0,0 +1,76 @@ +#!/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 . + +# TODO: Maybe check all existing languages instead of using a paremter +# TODO: Add a basepath to the files (this script should be callable from +# everyhwere +# TODO: Use a XML parser instead of reading lines + +if ARGV.length != 1 then + puts "Which language should be checked...?" + exit +end + +language = ARGV[0] + +original_file = "../res/values/strings.xml" +language_file = "../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 +items = [] + +pattern = Regexp.new '([^<]+)' + +file = File.new(original_file, 'r') +while line = file.gets + result = pattern.match line + if !result.nil? then + items.push result[1] + end +end +file.close + +puts "Found #{items.length} items in strings.xml" + +puts "Checking #{language}" +check = items.clone + +file = File.new(language_file, 'r') +while line = file.gets + result = pattern.match line + if !result.nil? then + check.delete result[1] + end +end + +percent = 100 - (100.to_f / items.length.to_f * check.length.to_f) + +if check.length == 0 then + puts "Language #{language} is OK (Translated: #{percent}%)" +else + puts "Language #{language} has missing translations (Translated: #{percent}%)" + check.each { |key| puts " #{key}" } +end +