po.rake
1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def extract_po_stat(name, text)
if text =~ /(\d+) #{name}/
return $1.to_i
else
return 0
end
end
namespace :po do
task :stats do
require 'term/ansicolor'
class PoOutput
include Term::ANSIColor
def ok(text)
print green, text, clear, "\n"
end
def not_ok(text)
print red, text, clear, "\n"
end
end
out = PoOutput.new
ENV['LANG'] = 'C'
puts "+----------+----------+------------+--------+--------------+"
puts "| Language | Messages | Translated | Fuzzy | Untranslated |"
puts "+----------+----------+------------+--------+--------------+"
Dir.glob(Rails.root.join('po', '*', 'noosfero.po')).each do |file|
language = File.basename(File.dirname(file))
output = `msgfmt --output /dev/null --statistics #{file} 2>&1`
translated = extract_po_stat('translated', output)
fuzzy = extract_po_stat('fuzzy', output)
untranslated = extract_po_stat('untranslated', output)
total = translated + fuzzy + untranslated
line = "| %-8s | %8d | %10d | %6d | %12d |" % [language, total, translated, fuzzy, untranslated]
if total == translated
out.ok(line)
else
out.not_ok(line)
end
end
puts "+----------+----------+------------+--------+--------------+"
end
end