website view lib/i18n-info.sh @ rev 1326

en/index.php: tiny edits
author Paul Issott <paul@slitaz.org>
date Sat Mar 17 09:36:44 2018 +0000 (2018-03-17)
parents 4d5e2d8fe3e6
children 2322a799c58e
line source
1 #!/bin/sh
3 # for english po statistics using `msgfmt --statistics`
4 LC_ALL=C; export LC_ALL
6 HG_URL="http://hg.slitaz.org"
7 INFO_FILE="/var/cache/slitaz/website/i18n.html"
8 mkdir -p "/var/cache/slitaz/website"
9 touch "${INFO_FILE}.new"
10 echo "" > "${INFO_FILE}.new"
12 # echo to file
13 echof()
14 {
15 echo "$@" >> "${INFO_FILE}.new"
16 }
18 # print table cells with 'pot' and 'po's
19 out_pot_po()
20 {
21 TMP_PO="/tmp/i18n.po"
22 # get all links to files in folder
23 LINKS=$(wget "$HG_URL/$PROJ_BASE/$PROJ_PODIR/" -q -O - | \
24 grep -A 1 "filename" | \
25 grep "href" | \
26 sed 's|.*"\([^"]*\)".*|http://hg.slitaz.org\1|g' | \
27 sed 's|/file/[^/]*/|/raw-file/tip/|g')
28 # get link to 'pot' and print cell
29 LINK_POT=$(echo "$LINKS" | grep -e '\.pot$')
31 echof "
32 <td class=\"pot\">
33 <a href=\"$LINK_POT\">
34 $(echo $LINK_POT | sed 's|.*/\([^/]*\.pot\)$|\1|')</a></td>
35 <td class=\"po\">"
37 # process 'po's
38 IFS="
39 "
40 for FILE in $(echo "$LINKS" | grep -e '.po$'); do
41 # temp download
42 wget $FILE -q -O $TMP_PO
43 # get stats
44 STAT=$(msgfmt --statistics $TMP_PO 2>&1 | sed 's|[^0-9 ]||g')
45 rm $TMP_PO
46 # language; number of translated and untranslated entries
47 LNG=$(echo $FILE | sed 's|.*/\([^/]*\)\.po$|\1|')
48 TRAN=$(echo $STAT | cut -d" " -f1)
49 UNTR=$(($(echo $STAT | awk '{print $2}') + 0))
50 # percents done
51 PCNT=$(($TRAN * 100 / ($TRAN + $UNTR)))
52 echof " <a href=\"$FILE\">$LNG<hr/>${PCNT}%</a>"
53 done
54 echof " </td>"
55 }
58 # print table cell with html documentations
59 out_doc()
60 {
61 # get all links to files in folder
62 LINKS=$(wget "$HG_URL/$PROJ_BASE/$PROJ_DOCDIR/" -q -O - | \
63 grep -A 1 "filename" | \
64 grep "href" | \
65 sed 's|.*"\([^"]*\)".*|http://hg.slitaz.org\1|g' | \
66 sed 's|/file/[^/]*/|/raw-file/tip/|g')
68 echof " <td class=\"docs\">"
70 IFS="
71 "
72 # get name of subproject, example: subproject 'tazusb-box' from 'tazusb'
73 SUB_PROJ=$(echo "$PROJ_PODIR" | sed 's|.*/\(.*\)|\1|')
74 for DOCUMENT in $(echo "$LINKS" | grep -e '.html$'); do
75 # strip project and subproject names from doc filename
76 NAME_DOC=$(echo $DOCUMENT | \
77 sed 's|.*/\([^/]*\)\.html$|\1|' | \
78 sed 's|'$PROJ_BASE'\.||; s|'$SUB_PROJ'\.||')
79 # first part of filename, example faq.en -> faq
80 NAME_DOC1=$(echo $NAME_DOC | cut -d"." -f1)
81 # second part of filename, faq.en -> en
82 NAME_DOC2=$(echo $NAME_DOC | cut -d"." -f2)
83 # if filename have only [lang] then rename it to doc.[lang]
84 if [ "$NAME_DOC1" == "$NAME_DOC2" ]; then
85 NAME_DOC1="doc"
86 fi
87 # not print 'linked' common documents, only localized ones
88 # (often link [project].html pointed to [project].en.html)
89 if [ "$NAME_DOC" != "$SUB_PROJ" ] && [ "$NAME_DOC" != "$PROJ_BASE" ]; then
90 echof " <a href=\"$DOCUMENT\">$NAME_DOC1<br/>$NAME_DOC2</a>"
91 fi
92 done
93 echof " </td>"
94 }
97 # print table cell with link to .desktop files
98 out_app()
99 {
100 APP_DIR="$HG_URL/$PROJ_BASE/file/tip/$PROJ_APPDIR"
101 PAGE=$(wget $APP_DIR -q -O -)
102 LINKS=$(echo "$PAGE" | grep -A 1 "filename" | grep "href" | wc -l)
103 # plural form
104 if [ "$LINKS" == "1" ]; then
105 APP_TEXT="1<br/>item"
106 else
107 APP_TEXT="$LINKS<br/>items"
108 fi
110 # rowspan: folder with desktop files is one for project
111 # combine all subprojects
112 echof " <td class=\"desk\"$ROWSPAN><a href=\"$APP_DIR\">$APP_TEXT</a></td>"
113 }
117 # standard path to folder with 'pot' and 'po's
118 S="file/tip/po"
119 # standard path to doc folder
120 D="file/tip/doc"
122 # list of all processed projects; fields description:
123 # [1]: Human readable project name (once)
124 # [2]: Project base: http://hg.slitaz.org/[2]
125 # [3]: Spanned cells (number or empty)
126 # [4]: Pot&po folder: http://hg.slitaz.org/[2]/[4]/
127 # [5]: Docs folder: http://hg.slitaz.org/[2]/[5]/
128 # [6]: Apps folder: http://hg.slitaz.org/[2]/file/tip/[6]/
129 PROJ_LIST="
130 SliTaz Base Files|slitaz-base-files||$S||rootfs/usr/share/applications
131 pkgs.slitaz.org|slitaz-forge/file/tip/pkgs||po||
132 SliTaz Pizza|slitaz-pizza||$S|$D|
133 SliTaz Tools|slitaz-tools|4|$S/slitaz-boxes||applications
134 |slitaz-tools||$S/slitaz-tools||
135 |slitaz-tools||$S/tazbox||
136 |slitaz-tools||$S/tazdrop||
137 SSFS|ssfs|2|$S/ssfs-server||data
138 |ssfs||$S/ssfs||
139 TazBug|tazbug||$S||data
140 TazLito|tazlito||$S|$D|applications
141 TazPanel|tazpanel||$S|$D|data
142 TazPkg|tazpkg||$S|$D|applications
143 TazUsb|tazusb|2|$S/tazusb|$D|applications
144 |tazusb||$S/tazusb-box||
145 TazInst|tazinst|3|$S/installer||applications
146 |tazinst||$S/slitaz-installer||
147 |tazinst||$S/tazinst|$D|
148 TazWeb|tazweb||$S|$D|data
149 TazIRC|tazirc||$S||data
150 CookUtils|cookutils||$S|$D|data
151 SliTaz boot scripts|slitaz-boot-scripts||||usr/share/applications
152 SliTaz Configs|slitaz-configs|3|$S||rootfs/usr/share/applications
153 |slitaz-configs||||rootfs/etc/xdg/openbox
154 |slitaz-configs||||rootfs/usr/share/webhome
155 SliTaz Doc|slitaz-doc|||slitaz|applications"
157 # print table header
158 echof "
159 <table>
160 <thead class=\"thead\">
161 <tr><td>Project</td>
162 <td>POT file</td>
163 <td>PO files</td>
164 <td>Docs</td>
165 <td>Menu</td>
166 </tr>
167 </thead>
168 <tbody>"
171 # main loop
172 IFS="
173 "
174 for PROJECT in $PROJ_LIST
175 do
176 IFS="|"
177 echo "$PROJECT" | while read P_NAME PROJ_BASE P_SPAN PROJ_PODIR PROJ_DOCDIR PROJ_APPDIR
178 do
179 if [ -n "$P_SPAN" ]; then
180 ROWSPAN=" rowspan=\"$P_SPAN\""
181 else
182 ROWSPAN=""
183 fi
185 echof -n " <tr>"
187 if [ -n "$P_NAME" ]; then
188 echof "<td$ROWSPAN class=\"proj\">
189 <a href=\"http://hg.slitaz.org/$PROJ_BASE\">$P_NAME</a></td>"
190 else
191 echof "<!-- td -->"
192 fi
194 # unconditional out pot and po
195 out_pot_po
197 # out doc if exists
198 if [ -n "$PROJ_DOCDIR" ]; then
199 out_doc
200 else
201 echof " <td class=\"docs\">&nbsp;</td>"
202 fi
204 # out apps if exists
205 if [ -n "$PROJ_APPDIR" ]; then
206 out_app
207 elif [ -n "$P_NAME" ]; then
208 echof " <td class=\"desk\">&nbsp;</td>"
209 fi
212 echof " </tr>"
214 IFS="
215 "
216 done
217 done
219 echof " </tbody>
220 </table>
221 <p>Updated: $(date '+%B %d, %Y @ %H:%M')</p>"
223 mv "${INFO_FILE}.new" "$INFO_FILE"
224 # the end