mirror of
https://github.com/moparisthebest/Yaaic
synced 2024-11-26 19:02:17 -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 = []
|
||||||
|
items = []
|
||||||
|
pattern = Regexp.new '<string name="([^"]+)">([^<]+)</string>'
|
||||||
|
lang_pattern = Regexp.new 'values-([a-zA-Z_-]+)'
|
||||||
|
|
||||||
|
# Scan for languages
|
||||||
|
Dir.new(base_path).entries.each { |directory|
|
||||||
|
result = lang_pattern.match directory
|
||||||
|
if !result.nil? then
|
||||||
|
languages.push result[1]
|
||||||
end
|
end
|
||||||
|
}
|
||||||
|
|
||||||
base_path = File.dirname(__FILE__)
|
puts "Found #{languages.length} language(s): #{languages.inspect}"
|
||||||
language = ARGV[0]
|
|
||||||
|
|
||||||
original_file = "#{base_path}/../res/values/strings.xml"
|
|
||||||
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,9 +48,12 @@ 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
|
||||||
|
languages.each { |language|
|
||||||
check = items.clone
|
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
|
||||||
@ -64,7 +63,7 @@ while line = file.gets
|
|||||||
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}%)"
|
||||||
@ -73,3 +72,6 @@ else
|
|||||||
check.each { |key| puts " #{key}" }
|
check.each { |key| puts " #{key}" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
puts
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user