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.

260 lines
9.5KB

  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 <http://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. for BRANCH in $BRANCHES; do
  24. echo -e "Repository: $BLUE$BRANCH"$ENDCOLOR
  25. STATSFILE="statistics-$BRANCH.html"
  26. ERRORS="translation-errors-$BRANCH"
  27. nerror=0; nwarn=0; npo=0; nt=0; nu=0; nf=0
  28. rm -f $STATSFILE
  29. echo -e "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"
  30. \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">
  31. <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">
  32. <head>
  33. <meta http-equiv=\"content-type\" content=\"application/xhtml+xml; charset=utf-8\" />
  34. <link rel=\"shortcut icon\" type=\"image/png\" href=\"http://www.wesnoth.org/mw/skins/glamdrol/ico.png\" />
  35. <title>Battle for Wesnoth</title>
  36. <style type=\"text/css\">@import url('images/main.css');</style>
  37. <link rel=\"stylesheet\" type=\"text/css\" href=\"images/old.css\" />
  38. </head>
  39. <body>
  40. <div id=\"global\">
  41. <div id=\"header\">
  42. <div id=\"logo\">
  43. <a href=\"http://www.wesnoth.org/\"><img alt=\"Wesnoth logo\" src=\"images/wesnoth-logo.jpg\" /></a>
  44. </div>
  45. </div>
  46. <div id=\"nav\">
  47. <ul>
  48. <li><a href=\"http://www.wesnoth.org/\">Home</a></li>
  49. <li><a href=\"http://www.wesnoth.org/wiki/Play\">Play</a></li>
  50. <li><a href=\"http://www.wesnoth.org/wiki/Create\">Create</a></li>
  51. <li><a href=\"http://www.wesnoth.org/forum/\">Forums</a></li>
  52. <li><a href=\"http://www.wesnoth.org/wiki/Support\">Support</a></li>
  53. <li><a href=\"http://www.wesnoth.org/wiki/Project\">Project</a></li>
  54. <li><a href=\"http://www.wesnoth.org/wiki/Credits\">Credits</a></li>
  55. </ul>
  56. </div>
  57. <h2 style=\"display:inline\">Wesnoth translation stats</h2>
  58. <div> <br/> </div><p style=\"display:inline\">Last update: <strong>
  59. `LC_TIME="en_US.UTF-8" date`
  60. </strong></p>
  61. <div> <br/> </div>
  62. <table class=\"main\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" width=\"100%\"><tr><td>
  63. <table cellspacing=\"1\" cellpadding=\"2\" border=\"0\" width=\"100%\">
  64. <tr class=\"header\">
  65. <td class=\"title\">File</td>
  66. <td class=\"title\" align=\"center\">Status</td>
  67. <td class=\"translated\">translated</td>
  68. <td class=\"translated\"><strong>%</strong></td>
  69. <td class=\"fuzzy\"><strong>fuzzy</strong></td>
  70. <td class=\"fuzzy\"><strong>%</strong></td>
  71. <td class=\"untranslated\"><strong>untranslated</strong></td>
  72. <td class=\"untranslated\"><strong>%</strong></td>
  73. <td class=\"title\">total</td>
  74. <td class=\"title\">graph</td>
  75. </tr>" >> $STATSFILE
  76. for files in $BRANCH/*.po; do
  77. file=`basename $files`
  78. filename=`basename $file .po`
  79. npo=$(($npo + 1)); has_errors="no"; has_warnings="no";
  80. # Extract the declared charset, may be we use this in future.
  81. charset=`sed -n '/^"Content-Type:/ s/.*charset=\([a-zA-Z0-9_-]*\).*/\1/p' "$BRANCH/$file"`
  82. echo -n "Checking $file for UTF-8 inconsistencies... "
  83. if $ISUTF8 < "$BRANCH/$file" > /dev/null 2>&1; then
  84. if ! echo $charset | grep -qi "UTF-8"; then
  85. has_errors="yes"
  86. echo -e $RED"FAILED; non UTF-8 charset declaration for UTF-8 content"$ENDCOLOR
  87. echo "$file: non UTF-8 charset declared for UTF-8 content; expect to see 'charset=UTF-8'." >> $ERRORS
  88. else
  89. echo -e $GREEN"OK"$ENDCOLOR
  90. fi
  91. else
  92. if echo $charset | grep -qi "UTF-8"; then
  93. has_errors="yes"
  94. echo -e $RED"FAILED; non UTF-8 content for UTF-8 charset declaration"$ENDCOLOR
  95. echo "$file: UTF-8 charset declared for non UTF-8 content; expect to see a non UTF-8 charset." >> $ERRORS
  96. else
  97. echo -e $GREEN"OK"$ENDCOLOR
  98. fi
  99. fi
  100. echo -n "Checking $file for odd characters... "
  101. if grep -nH $ODD_CHARS "$BRANCH/$file" >> $ERRORS; then
  102. has_warnings="yes"
  103. echo -e $RED"FAILED; odd characters found"$ENDCOLOR
  104. echo "$file: one or more odd character from the '$ODD_CHARS' set found." >> $ERRORS
  105. else
  106. echo -e $GREEN"OK"$ENDCOLOR
  107. fi
  108. # Makes sense only if the file passed the UTF-8 check.
  109. if [ "$has_errors" = "no" ]; then
  110. echo -n "Checking $file with msgfmt... "
  111. if ! LC_MESSAGES=C $MSGFMT --check -o /dev/null "$BRANCH/$file" >> $ERRORS; then
  112. has_errors="yes"
  113. echo -e $RED"FAILED"$ENDCOLOR
  114. else
  115. echo -e $GREEN"OK"$ENDCOLOR
  116. fi
  117. fi
  118. r=0; rf=0; ru=0; t=0; u=0; f=0; rt=0
  119. if [ "$has_errors" = "yes" ]; then
  120. nerror=$(($nerror + 1))
  121. sum=0
  122. st="Error"
  123. if [ $STATUS = "OK" ]; then
  124. STATUS="Error"
  125. fi
  126. if [ $STATUS = "Warning" ]; then
  127. STATUS="Error"
  128. fi
  129. else
  130. stat=`LC_MESSAGES=C $MSGFMT --statistics -o /dev/null "$BRANCH/$file" 2>&1`
  131. t=`echo "$stat" | sed -ne 's/\([0-9]\+\) translated .*/\1/p'`; t=${t:-0}
  132. u=`echo "$stat" | sed -ne 's/.* \([0-9]\+\) untranslated .*/\1/p'`; u=${u:-0}
  133. f=`echo "$stat" | sed -ne 's/.* \([0-9]\+\) fuzzy translation.*/\1/p'`; f=${f:-0}
  134. sum=$(($t + $f + $u))
  135. if [ ! "$sum" -eq 0 ]; then
  136. rt=`printf '%s%d%s%d\n' "scale=2; 100*" $t "/" $sum | bc`
  137. fi
  138. if [ ! "$sum" -eq 0 ]; then
  139. rf=`printf '%s%d%s%d\n' "scale=2; 100*" $f "/" $sum | bc`
  140. fi
  141. if [ ! "$sum" -eq 0 ]; then
  142. ru=`printf '%s%d%s%d\n' "scale=2; 100*" $u "/" $sum | bc`
  143. fi
  144. nt=$(($nt + $t)); nu=$(($nu + $u)); nf=$(($nf + $f))
  145. st="OK"
  146. if [ "$has_warnings" = "yes" ]; then
  147. nwarn=$(($nwarn + 1))
  148. st='Warning'
  149. if [ "$STATUS" = "OK" ]; then
  150. STATUS='Warning'
  151. fi
  152. fi
  153. fi
  154. echo "<tr class=\"row-$CL\">" >> $STATSFILE
  155. CL=$(( ($CL+1)%2 ))
  156. echo " <td align=\"left\"><strong><a href=\""$BRANCH/$filename.po"\">`basename $filename`</a></strong></td>
  157. <td class=\"percentage-$CL\" align=\"center\">$st</td>
  158. <td class=\"row-$CL\" align=\"right\">$t</td>" >> $STATSFILE
  159. printf '%s%d%s%.2f%s\n' " <td class=\"percentage-" $CL "\" align=\"right\">" $rt "</td>" >> $STATSFILE
  160. echo " <td class=\"row-$CL\" align=\"right\">$f</td>" >> $STATSFILE
  161. printf '%s%d%s%.2f%s\n' " <td class=\"percentage-" $CL "\" align=\"right\">" $rf "</td>" >> $STATSFILE
  162. echo " <td class=\"row-$CL\" align=\"right\">$u</td>" >> $STATSFILE
  163. printf '%s%d%s%.2f%s\n' " <td class=\"percentage-" $CL "\" align=\"right\">" $ru "</td>" >> $STATSFILE
  164. echo " <td class=\"row-$CL\" align=\"right\">$sum</td>" >> $STATSFILE
  165. n4=`printf '%s%f\n' "scale=2; 3*" $rt | bc`
  166. n6=`printf '%s%f\n' "scale=2; 3*" $rf | bc`
  167. n8=`printf '%s%f\n' "scale=2; 3*" $ru | bc`
  168. printf '%s%.2f%s%.2f%s%.2f%s\n' " <td><img src=\"images/green.png\" height=\"15\" width=\"" $n4 "\" alt=\"translated\"/><img src=\"images/blue.png\" height=\"15\" width=\"" $n6 "\" alt=\"fuzzy\"/><img src=\"images/red.png\" height=\"15\" width=\"" $n8 "\" alt=\"untranslated\"/></td>" >> $STATSFILE
  169. echo "</tr>" >> $STATSFILE
  170. done
  171. if [ "$npo" -eq 0 ]; then
  172. echo -e $RED"No '${PO}.po' file under '$BRANCH'."$ENDCOLOR
  173. exit 0
  174. fi
  175. if [ "$nerror" -gt 0 ]; then
  176. echo -n -e $RED"Fatal errors found. See '"
  177. tput smso; echo -n "$ERRORS"; tput rmso
  178. echo -ne "' for details."$ENDCOLOR
  179. echo ""
  180. else
  181. echo -ne $GREEN"No fatal errors found."$ENDCOLOR
  182. echo ""
  183. if [ -s "$ERRORS" ]; then
  184. echo -n -e $RED" See '"
  185. tput smso; echo -n "$ERRORS"; tput rmso
  186. echo -ne "' for warnings."$ENDCOLOR
  187. echo ""
  188. else
  189. rm -f $ERRORS
  190. fi
  191. fi
  192. if [ "$npo" = "$nerror" ]; then
  193. echo -en $RED"All files have fatal errors."$ENDCOLOR
  194. echo ""
  195. else
  196. sum=$((${nt} + ${nf} + ${nu}))
  197. nrt=`printf '%s%d%s%d\n' "scale=2; 100*" $nt "/" $sum | bc`
  198. nrf=`printf '%s%d%s%d\n' "scale=2; 100*" $nf "/" $sum | bc`
  199. nru=`printf '%s%d%s%d\n' "scale=2; 100*" $nu "/" $sum | bc`
  200. echo "<tr class=\"title\">
  201. <td align=\"left\"><strong>Total</strong></td>
  202. <td align=\"center\"><strong>$STATUS</strong></td>
  203. <td align=\"right\"><strong>$nt</strong></td>" >> $STATSFILE
  204. printf '%s%.2f%s\n' "<td align=\"right\"><strong>" $nrt "</strong></td>" >> $STATSFILE
  205. echo "<td align=\"right\"><strong>$nf</strong></td>" >> $STATSFILE
  206. printf '%s%.2f%s\n' "<td align=\"right\"><strong>" $nrf "</strong></td>" >> $STATSFILE
  207. echo "<td align=\"right\"><strong>$nu</strong></td>" >> $STATSFILE
  208. printf '%s%.2f%s\n' "<td align=\"right\"><strong>" $nru "</strong></td>" >> $STATSFILE
  209. echo "<td align=\"right\"><strong>$((${nt} + ${nf} + ${nu}))</strong></td>" >> $STATSFILE
  210. nrt=`printf '%s%f\n' "scale=2; 3*" $nrt | bc`
  211. nrf=`printf '%s%f\n' "scale=2; 3*" $nrf | bc`
  212. nru=`printf '%s%f\n' "scale=2; 3*" $nru | bc`
  213. printf '%s%.2f%s%.2f%s%.2f%s\n' "<td><img src=\"images/green.png\" height=\"15\" width=\"" $nrt "\" alt=\"translated\"/><img src=\"images/blue.png\" height=\"15\" width=\"" $nrf "\" alt=\"fuzzy\"/><img src=\"images/red.png\" height=\"15\" width=\"" $nru "\" alt=\"untranslated\"/></td>" >> $STATSFILE
  214. echo "</tr>
  215. </table>
  216. </td>
  217. </tr>
  218. </table>
  219. <div><br/></div>
  220. <div id=\"footer\">
  221. <div id=\"footnote\">
  222. &copy; 2003-"`date +%Y`" The Battle for Wesnoth<br/>
  223. <br/>
  224. </div>
  225. </div>
  226. </div>
  227. </body>
  228. </html>" >> $STATSFILE
  229. fi
  230. done
  231. # Exit with error count just because it may sense.
  232. exit $nerror