| 1 |
#!/usr/bin/env ruby |
| 2 |
# |
| 3 |
# Generate statistics of Amarok's localizations |
| 4 |
# |
| 5 |
# Copyright (C) 2007 Harald Sitter <sitter.harald@gmail.com> |
| 6 |
# |
| 7 |
# This program is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 2 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# This program is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program; if not, write to the Free Software |
| 19 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 20 |
|
| 21 |
require 'fileutils' |
| 22 |
|
| 23 |
if $*.empty?() |
| 24 |
puts "generate_l10nstats.rb [amarokversion]" |
| 25 |
exit 1 |
| 26 |
end |
| 27 |
|
| 28 |
@version = $*[0] |
| 29 |
@clang = -2 |
| 30 |
@cfuzzy = 0 |
| 31 |
@cuntrans = 0 |
| 32 |
@cnotshow = 0 |
| 33 |
@cper = 0 |
| 34 |
@file = "../amarok-#{@version}.html" |
| 35 |
|
| 36 |
def setmaindir() |
| 37 |
@maindir = Dir.pwd |
| 38 |
end |
| 39 |
|
| 40 |
def calcpercentage( per ) |
| 41 |
unless @cper == "0" |
| 42 |
@cper = ((@cper + per) / 2) |
| 43 |
else |
| 44 |
@cper = per |
| 45 |
end |
| 46 |
end |
| 47 |
|
| 48 |
# write HTML header part |
| 49 |
def header() |
| 50 |
`echo ' |
| 51 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 52 |
<html> |
| 53 |
<head> |
| 54 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| 55 |
<title>Statistics of Amarok #{@version} translations</title> |
| 56 |
</head> |
| 57 |
<body> |
| 58 |
<a name="__top"> |
| 59 |
<p align="center"> |
| 60 |
<a name="statistics of amarok #{@version} translations"> |
| 61 |
<h1>Statistics of Amarok #{@version} translations</h1><br> |
| 62 |
<table border="1" cellspacing="0"dir="ltr"> |
| 63 |
<tr> |
| 64 |
<td align="left" valign="middle" width="60" height="12"> |
| 65 |
<font color="#196aff"><i><b>Language</b></i></font> |
| 66 |
</td> |
| 67 |
<td align="center" valign="middle" width="142" height="12"> |
| 68 |
<font color="#196aff"><i><b>Fuzzy Strings</b></i></font> |
| 69 |
</td> |
| 70 |
<td align="center" valign="middle" width="168" height="12"> |
| 71 |
<font color="#196aff"><i><b>Untranslated Strings</b></i></font> |
| 72 |
</td> |
| 73 |
<td align="center" valign="middle" width="163" height="12"> |
| 74 |
<font color="#196aff"><i><b>All Not Shown Strings</b></i></font> |
| 75 |
</td> |
| 76 |
<td align="center" valign="middle" width="163" height="12"> |
| 77 |
<font color="#196aff"><i><b>Translated %</b></i></font> |
| 78 |
</td> |
| 79 |
</tr>' > #{@file}` |
| 80 |
end |
| 81 |
|
| 82 |
# write HTML footer part |
| 83 |
def footer() |
| 84 |
`echo " |
| 85 |
<tr> |
| 86 |
<td align="left" valign="middle" width="60" height="12"> |
| 87 |
<u><i><b>#{@clang}</b></i></u> |
| 88 |
</td> |
| 89 |
<td align="center" valign="middle" width="142" height="12"> |
| 90 |
<u><i><b> |
| 91 |
#{if @cfuzzy == "0" then |
| 92 |
"0" |
| 93 |
else |
| 94 |
@cfuzzy |
| 95 |
end} |
| 96 |
</b></i></u> |
| 97 |
</td> |
| 98 |
<td align="center" valign="middle" width="168" height="12"> |
| 99 |
<u><i><b> |
| 100 |
#{if @cuntrans == "0" then |
| 101 |
"0" |
| 102 |
else |
| 103 |
@cuntrans |
| 104 |
end} |
| 105 |
</b></i></u> |
| 106 |
</td> |
| 107 |
<td align="center" valign="middle" width="163" height="12"> |
| 108 |
<u><i><b> |
| 109 |
#{if @cnotshow == "0" then |
| 110 |
"0" |
| 111 |
else |
| 112 |
@cnotshow |
| 113 |
end} |
| 114 |
</b></i></u> |
| 115 |
</td> |
| 116 |
<td align="center" valign="middle" width="163" height="12"> |
| 117 |
<u><i><b> |
| 118 |
#{if @cper == "0" then |
| 119 |
"0" |
| 120 |
else |
| 121 |
@cper.to_s + " %" |
| 122 |
end} |
| 123 |
</b></i></u> |
| 124 |
</td> |
| 125 |
</tr>" >> #{@file}` |
| 126 |
end |
| 127 |
|
| 128 |
def stats( lang ) |
| 129 |
values = nil |
| 130 |
|
| 131 |
if lang != "." and lang != ".." then |
| 132 |
Dir.chdir("po/#{lang}") |
| 133 |
|
| 134 |
# grab statistics data |
| 135 |
`msgfmt --statistics amarok.po 2> tmp.txt` |
| 136 |
term = `cat tmp.txt` |
| 137 |
File.delete("tmp.txt") |
| 138 |
|
| 139 |
# rape the data and create some proper variables |
| 140 |
values = term.scan(/[\d]+/) |
| 141 |
notshow = values[1].to_i + values[2].to_i |
| 142 |
all = values[0].to_i + values[1].to_i + values[2].to_i |
| 143 |
show = all - notshow |
| 144 |
per = ((100.0 * show.to_f) / all.to_f) |
| 145 |
|
| 146 |
# assign font colors according to translation status |
| 147 |
# TODO: replace with case -> point out how to do with relational operators |
| 148 |
if per == 100 then |
| 149 |
fcolor = "#00B015" #green |
| 150 |
elsif per >= 95 then |
| 151 |
fcolor = "#FF9900" #orange |
| 152 |
elsif per >= 75 then |
| 153 |
fcolor = "#6600FF" #blue |
| 154 |
elsif per >= 50 then |
| 155 |
fcolor = "#000000" #black |
| 156 |
else |
| 157 |
fcolor = "#FF0000" #red |
| 158 |
end |
| 159 |
|
| 160 |
Dir.chdir(@maindir) |
| 161 |
|
| 162 |
`echo " |
| 163 |
<tr> |
| 164 |
<td align="left" valign="middle" width="60" height="12"> |
| 165 |
<font color="#{fcolor}"> |
| 166 |
#{lang} |
| 167 |
</font> |
| 168 |
</td> |
| 169 |
<td align="center" valign="middle" width="142" height="12"> |
| 170 |
<font color="#{fcolor}"> |
| 171 |
#{if values[1] == nil then |
| 172 |
"0" |
| 173 |
else |
| 174 |
values[1] |
| 175 |
end} |
| 176 |
</font> |
| 177 |
</td> |
| 178 |
<td align="center" valign="middle" width="168" height="12"> |
| 179 |
<font color="#{fcolor}"> |
| 180 |
#{if values[2] == nil then |
| 181 |
"0" |
| 182 |
else |
| 183 |
values[2] |
| 184 |
end} |
| 185 |
</font> |
| 186 |
</td> |
| 187 |
<td align="center" valign="middle" width="163" height="12"> |
| 188 |
<font color="#{fcolor}"> |
| 189 |
#{if notshow == nil then |
| 190 |
"0" |
| 191 |
else |
| 192 |
notshow |
| 193 |
end} |
| 194 |
</font> |
| 195 |
</td> |
| 196 |
<td align="center" valign="middle" width="163" height="12"> |
| 197 |
<font color="#{fcolor}"> |
| 198 |
#{if per == 0 then |
| 199 |
"0 %" |
| 200 |
else |
| 201 |
per.to_i.to_s + " %" |
| 202 |
end} |
| 203 |
</font> |
| 204 |
</td> |
| 205 |
</tr>" >> #{@file}` |
| 206 |
|
| 207 |
# update countin variables |
| 208 |
@cfuzzy += values[1].to_i |
| 209 |
@cuntrans += values[2].to_i |
| 210 |
@cnotshow += notshow.to_i |
| 211 |
@clang += 1 |
| 212 |
calcpercentage( per.to_i ) |
| 213 |
|
| 214 |
end |
| 215 |
end |
| 216 |
|
| 217 |
puts "Untaring the tarball..." |
| 218 |
`tar -xf amarok-#{@version}.tar.bz2` |
| 219 |
Dir.chdir("amarok-#{@version}") |
| 220 |
File.delete("po/Makefile.am", "po/Makefile.in") |
| 221 |
setmaindir() |
| 222 |
|
| 223 |
puts "Writing the header..." |
| 224 |
header() |
| 225 |
|
| 226 |
puts "Writing the statistics..." |
| 227 |
langs = Dir.entries("po") |
| 228 |
Dir.foreach("po") {|lang| |
| 229 |
stats( lang ) |
| 230 |
} |
| 231 |
|
| 232 |
puts "Writing the footer..." |
| 233 |
footer() |
| 234 |
|
| 235 |
puts "Cleaning up..." |
| 236 |
Dir.chdir( "../" ) |
| 237 |
FileUtils.rm_r( "amarok-#{@version}" ) |
| 238 |
|
| 239 |
puts "Generation finished..." |
| 240 |
|
| 241 |
exit 0 |