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