Wesnoth localization tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

statistics 9.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. #!/bin/bash
  2. # Check translations, generate verbose statistics.
  3. # Copyright (C) 2004 Recai Oktas <roktas@omu.edu.tr>
  4. # Copyright (C) 2007-2008 Andrius Štikonas <stikonas@gmail.com> (my code can also be used under GPLv3 or any later)
  5. # MediaWiki 'glamdrol' style sheet Copyright (C) 2005 by Jordą Polo <jorda AT ettin DOT org> Based on 'monobook', by Gabriel Wicke
  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 version 2 as published by
  9. # the Free Software Foundation.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. source "$(dirname $0)/variables"
  19. LC_ALL=C
  20. ODD_CHARS='�'
  21. CL=0 # counter for css style
  22. STATUS="OK" # Total status of translations
  23. while getopts ":c" opt; do
  24. case $opt in
  25. c)
  26. CORE_TEXTDOMAINS="wesnoth lib editor help ai units multiplayer anl tutorial" ;;
  27. esac
  28. done
  29. for BRANCH in $BRANCHES; do
  30. echo -e "Repository: $BLUE$BRANCH"$ENDCOLOR
  31. STATSFILE="statistics-$BRANCH.html"
  32. ERRORS="translation-errors-$BRANCH"
  33. nerror=0; nwarn=0; npo=0; nt=0; nu=0; nf=0
  34. rm -f $STATSFILE
  35. echo -e "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
  36. \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
  37. <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
  38. <head>
  39. <meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=utf-8\" />
  40. <title>Battle for Wesnoth</title>
  41. <link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.wesnoth.org/wesmere/css/wesmere-1.1.0.css\" />
  42. <link rel=\"stylesheet\" type=\"text/css\" href=\"https://www.wesnoth.org/wesmere/css/gettext-1.1.0.css\" />
  43. </head>
  44. <body>
  45. <div id=\"main\">
  46. <div id=\"nav\" role=\"banner\">
  47. <div class=\"centerbox\">
  48. <div id=\"logo\">
  49. <a href=\"https://www.wesnoth.org/\" aria-label=\"Wesnoth logo\"></a>
  50. </div>
  51. <div id=\"nav\">
  52. <ul>
  53. <li><a href=\"https://www.wesnoth.org/\">Home</a></li>
  54. <li><a href=\"https://www.wesnoth.org/wiki/Play\">Play</a></li>
  55. <li><a href=\"https://www.wesnoth.org/wiki/Create\">Create</a></li>
  56. <li><a href=\"https://www.wesnoth.org/forum/\">Forums</a></li>
  57. <li><a href=\"https://www.wesnoth.org/wiki/Support\">Support</a></li>
  58. <li><a href=\"https://www.wesnoth.org/wiki/Project\">Project</a></li>
  59. <li><a href=\"https://www.wesnoth.org/wiki/Credits\">Credits</a></li>
  60. </ul>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. <h1 style=\"display:inline\">Wesnoth translation stats</h1>
  66. <div> <br/> </div><p style=\"display:inline\">Last update: <strong>
  67. $(LC_TIME="en_US.UTF-8" date)
  68. </strong></p>
  69. <div> <br/> </div>
  70. <table class=\"gettext-stats\">
  71. <thead><thead><tr>
  72. <th class=\"title\" scope=\"col\">Textdomain</th>
  73. <th scope=\"col\">Status</th>
  74. <th class=\"translated\" scope=\"col\">Translated</th>
  75. <th class=\"translated percent\" scope=\"col\">%</th>
  76. <th class=\"fuzzy\" scope=\"col\">Fuzzy</th>
  77. <th class=\"fuzzy percent\" scope=\"col\">%</th>
  78. <th class=\"untranslated\" scope=\"col\">Untranslated</th>
  79. <th class=\"untranslated percent\" scope=\"col\">%</th>
  80. <th class=\"strcount\" scope=\"col\">Total</th>
  81. <th class=\"graph\" scope=\"col\">Graph</th></tr></thead>
  82. <tbody><tr>" >> $STATSFILE
  83. if [ -n "$CORE_TEXTDOMAINS" ]; then
  84. POFILES=$BRANCH/$(echo $CORE_TEXTDOMAINS | awk '$NF=$NF "*.po"' OFS="*.po $BRANCH/")
  85. else
  86. POFILES="$BRANCH/*.po"
  87. fi
  88. for files in $POFILES; do
  89. file=$(basename $files)
  90. filename=$(basename $file .po)
  91. npo=$(($npo + 1)); has_errors="no"; has_warnings="no";
  92. # Extract the declared charset, may be we use this in future.
  93. charset=$(sed -n '/^"Content-Type:/ s/.*charset=\([a-zA-Z0-9_-]*\).*/\1/p' "$BRANCH/$file")
  94. echo -n "Checking $file for UTF-8 inconsistencies... "
  95. if $ISUTF8 < "$BRANCH/$file" > /dev/null 2>&1; then
  96. if ! echo $charset | grep -qi "UTF-8"; then
  97. has_errors="yes"
  98. echo -e $RED"FAILED; non UTF-8 charset declaration for UTF-8 content"$ENDCOLOR
  99. echo "$file: non UTF-8 charset declared for UTF-8 content; expect to see 'charset=UTF-8'." >> $ERRORS
  100. else
  101. echo -e $GREEN"OK"$ENDCOLOR
  102. fi
  103. else
  104. if echo $charset | grep -qi "UTF-8"; then
  105. has_errors="yes"
  106. echo -e $RED"FAILED; non UTF-8 content for UTF-8 charset declaration"$ENDCOLOR
  107. echo "$file: UTF-8 charset declared for non UTF-8 content; expect to see a non UTF-8 charset." >> $ERRORS
  108. else
  109. echo -e $GREEN"OK"$ENDCOLOR
  110. fi
  111. fi
  112. echo -n "Checking $file for odd characters... "
  113. if grep -nH $ODD_CHARS "$BRANCH/$file" >> $ERRORS; then
  114. has_warnings="yes"
  115. echo -e $RED"FAILED; odd characters found"$ENDCOLOR
  116. echo "$file: one or more odd character from the '$ODD_CHARS' set found." >> $ERRORS
  117. else
  118. echo -e $GREEN"OK"$ENDCOLOR
  119. fi
  120. # Makes sense only if the file passed the UTF-8 check.
  121. if [ "$has_errors" = "no" ]; then
  122. echo -n "Checking $file with msgfmt... "
  123. if ! LC_MESSAGES=C $MSGFMT --check -o /dev/null "$BRANCH/$file" >> $ERRORS; then
  124. has_errors="yes"
  125. echo -e $RED"FAILED"$ENDCOLOR
  126. else
  127. echo -e $GREEN"OK"$ENDCOLOR
  128. fi
  129. fi
  130. r=0; rf=0; ru=0; t=0; u=0; f=0; rt=0
  131. if [ "$has_errors" = "yes" ]; then
  132. nerror=$(($nerror + 1))
  133. sum=0
  134. st="Error"
  135. if [ $STATUS = "OK" ]; then
  136. STATUS="Error"
  137. fi
  138. if [ $STATUS = "Warning" ]; then
  139. STATUS="Error"
  140. fi
  141. else
  142. stat=$(LC_MESSAGES=C $MSGFMT --statistics -o /dev/null "$BRANCH/$file" 2>&1)
  143. t=$(echo "$stat" | sed -ne 's/\([0-9]\+\) translated .*/\1/p'); t=${t:-0}
  144. u=$(echo "$stat" | sed -ne 's/.* \([0-9]\+\) untranslated .*/\1/p'); u=${u:-0}
  145. f=$(echo "$stat" | sed -ne 's/.* \([0-9]\+\) fuzzy translation.*/\1/p'); f=${f:-0}
  146. sum=$(($t + $f + $u))
  147. if [ ! "$sum" -eq 0 ]; then
  148. rt=$(printf '%s%d%s%d\n' "scale=2; 100*" $t "/" $sum | bc)
  149. fi
  150. if [ ! "$sum" -eq 0 ]; then
  151. rf=$(printf '%s%d%s%d\n' "scale=2; 100*" $f "/" $sum | bc)
  152. fi
  153. if [ ! "$sum" -eq 0 ]; then
  154. ru=$(printf '%s%d%s%d\n' "scale=2; 100*" $u "/" $sum | bc)
  155. fi
  156. nt=$(($nt + $t)); nu=$(($nu + $u)); nf=$(($nf + $f))
  157. st="OK"
  158. if [ "$has_warnings" = "yes" ]; then
  159. nwarn=$(($nwarn + 1))
  160. st='Warning'
  161. if [ "$STATUS" = "OK" ]; then
  162. STATUS='Warning'
  163. fi
  164. fi
  165. fi
  166. echo "<tr class=\"row-$CL\">" >> $STATSFILE
  167. CL=$(( ($CL+1)%2 ))
  168. echo " <td class=\"textdomain-name\" align=\"left\"><strong><a href=\""$BRANCH/$filename.po"\">$(basename $filename)</a></strong></td>
  169. <td align=\"center\">$st</td>
  170. <td class=\"translated\" align=\"right\">$t</td>" >> $STATSFILE
  171. printf '%s%.2f%s\n' " <td class=\"percent\" align=\"right\">" $rt "</td>" >> $STATSFILE
  172. echo " <td class=\"fuzzy\" align=\"right\">$f</td>" >> $STATSFILE
  173. printf '%s%.2f%s\n' " <td class=\"percent\" align=\"right\">" $rf "</td>" >> $STATSFILE
  174. echo " <td class=\"untranslated\" align=\"right\">$u</td>" >> $STATSFILE
  175. printf '%s%.2f%s\n' " <td class=\"percent\" align=\"right\">" $ru "</td>" >> $STATSFILE
  176. echo " <td class=\"strcount\" align=\"right\">$sum</td>" >> $STATSFILE
  177. n4=$(printf '%s%f\n' "scale=2; 9*" $rt | bc)
  178. n6=$(printf '%s%f\n' "scale=2; 9*" $rf | bc)
  179. n8=$(printf '%s%f\n' "scale=2; 9*" $ru | bc)
  180. printf '%s%.2f%s%.2f%s%.2f%s\n' " <td class=\"graph\"><span class=\"stats-bar green-bar\" style=\"width:" $n4 "px\"></span><span class=\"stats-bar blue-bar\" style=\"width:" $n6 "px\"></span><span class=\"stats-bar red-bar\" style=\"width:" $n8 "px\"></span></td>" >> $STATSFILE
  181. echo "</tr>" >> $STATSFILE
  182. done
  183. if [ "$npo" -eq 0 ]; then
  184. echo -e $RED"No '${PO}.po' file under '$BRANCH'."$ENDCOLOR
  185. exit 0
  186. fi
  187. if [ "$nerror" -gt 0 ]; then
  188. echo -n -e $RED"Fatal errors found. See '"
  189. tput smso; echo -n "$ERRORS"; tput rmso
  190. echo -ne "' for details."$ENDCOLOR
  191. echo ""
  192. else
  193. echo -ne $GREEN"No fatal errors found."$ENDCOLOR
  194. echo ""
  195. if [ -s "$ERRORS" ]; then
  196. echo -n -e $RED" See '"
  197. tput smso; echo -n "$ERRORS"; tput rmso
  198. echo -ne "' for warnings."$ENDCOLOR
  199. echo ""
  200. else
  201. rm -f $ERRORS
  202. fi
  203. fi
  204. if [ "$npo" = "$nerror" ]; then
  205. echo -en $RED"All files have fatal errors."$ENDCOLOR
  206. echo ""
  207. else
  208. sum=$((${nt} + ${nf} + ${nu}))
  209. nrt=$(printf '%s%d%s%d\n' "scale=2; 100*" $nt "/" $sum | bc)
  210. nrf=$(printf '%s%d%s%d\n' "scale=2; 100*" $nf "/" $sum | bc)
  211. nru=$(printf '%s%d%s%d\n' "scale=2; 100*" $nu "/" $sum | bc)
  212. echo "<tfoot><tr class=\"teamstats\">
  213. <th class=\"title\" scope=\"row\">Total</th>
  214. <td align=\"center\">$STATUS</td>
  215. <td class=\"translated\">$nt</td>" >> $STATSFILE
  216. printf '%s%.2f%s\n' "<td align=\"right\">" $nrt "</td>" >> $STATSFILE
  217. echo "<td class=\"fuzzy\">$nf</td>" >> $STATSFILE
  218. printf '%s%.2f%s\n' "<td align=\"right\">" $nrf "</td>" >> $STATSFILE
  219. echo "<td class=\"untranslated\">$nu</td>" >> $STATSFILE
  220. printf '%s%.2f%s\n' "<td align=\"right\">" $nru "</td>" >> $STATSFILE
  221. echo "<td class=\"strcount\">$((${nt} + ${nf} + ${nu}))</td>" >> $STATSFILE
  222. nrt=$(printf '%s%f\n' "scale=2; 9*" $nrt | bc)
  223. nrf=$(printf '%s%f\n' "scale=2; 9*" $nrf | bc)
  224. nru=$(printf '%s%f\n' "scale=2; 9*" $nru | bc)
  225. printf '%s%.2f%s%.2f%s%.2f%s\n' " <td class=\"graph\"><span class=\"stats-bar green-bar\" style=\"width:" $nrt "px\"></span><span class=\"stats-bar blue-bar\" style=\"width:" $nrf "px\"></span><span class=\"stats-bar red-bar\" style=\"width:" $nru "px\"></span></td>" >> $STATSFILE
  226. echo "</tr>
  227. </table>
  228. </td>
  229. </tr>
  230. </table>
  231. <div><br/></div>
  232. <div id=\"footer\">
  233. <div id=\"footnote\">
  234. &copy; 2003-"$(date +%Y)" The Battle for Wesnoth<br/>
  235. Site design Copyright © 2017–2018 by Iris Morelle.
  236. <br/>
  237. </div>
  238. </div>
  239. </div>
  240. </body>
  241. </html>" >> $STATSFILE
  242. fi
  243. done
  244. # Exit with error count just because it may sense.
  245. exit $nerror