Runa A. Sandvik commited on 2009-08-16 10:11:41
Zeige 2 geänderte Dateien mit 377 Einfügungen und 0 Löschungen.
... | ... |
@@ -0,0 +1,131 @@ |
1 |
+#!/bin/bash |
|
2 |
+# |
|
3 |
+# Author: Runa Sandvik, <runa.sandvik@gmail.com> |
|
4 |
+# Google Summer of Code 2009 |
|
5 |
+# |
|
6 |
+# This is Free Software (GPLv3) |
|
7 |
+# http://www.gnu.org/licenses/gpl-3.0.txt |
|
8 |
+# |
|
9 |
+# This script will convert all the translated po files back to wml |
|
10 |
+# files. |
|
11 |
+# |
|
12 |
+# For more information, see the HOWTO and README in |
|
13 |
+# translation/tools/gsoc09. |
|
14 |
+# |
|
15 |
+ |
|
16 |
+### start config ### |
|
17 |
+ |
|
18 |
+# Location of the wml files |
|
19 |
+wmldir="$PWD" |
|
20 |
+ |
|
21 |
+# Location of the po files, |
|
22 |
+podir="`dirname $wmldir`/translation/projects/website" |
|
23 |
+ |
|
24 |
+# A lot of the wml files have custom tags. These tags have been defined |
|
25 |
+# in website/include/versions.wmi. Tags that people usually forget to close, |
|
26 |
+# as well as tags that are not defined in versions.wmi have been added. |
|
27 |
+# See: https://svn.torproject.org/svn/website/trunk/include/versions.wmi |
|
28 |
+customtag=`echo $(cat "$wmldir/include/versions.wmi" | awk '{ printf "<%s> " , $2 }' | sed 's/<>//g') "<svnsandbox> <svnwebsite> <input> <hr> <br> <img>"` |
|
29 |
+ |
|
30 |
+# We also need to use the nodefault option of po4a; space separated list |
|
31 |
+# of tags that the module should not try to set by default in any |
|
32 |
+# category. For now, we only need the input tag. |
|
33 |
+nodefault='<input>' |
|
34 |
+ |
|
35 |
+### end config ### |
|
36 |
+ |
|
37 |
+# Create a lockfile to make sure that only one instance of the script |
|
38 |
+# can run at any time. |
|
39 |
+LOCKFILE=po2wml.lock |
|
40 |
+ |
|
41 |
+if lockfile -! -l 60 -r 3 "$LOCKFILE"; |
|
42 |
+then |
|
43 |
+ echo "unable to acquire lock" >2 |
|
44 |
+ exit 1 |
|
45 |
+fi |
|
46 |
+ |
|
47 |
+trap "rm -f '$PWD/$LOCKFILE'" exit |
|
48 |
+ |
|
49 |
+# Check if translation/projects/website exist, i.e. has been checked out |
|
50 |
+if [ ! -d $podir ] |
|
51 |
+then |
|
52 |
+ echo "Have you remembered to check out translation/projects/website?" |
|
53 |
+ exit 1 |
|
54 |
+fi |
|
55 |
+ |
|
56 |
+# cd to the right directory so we can commit the files later |
|
57 |
+cd "$wmldir" |
|
58 |
+ |
|
59 |
+# We need to find the po files |
|
60 |
+po=`find $podir -regex '^'$podir'/.*/.*\.po' -type f` |
|
61 |
+ |
|
62 |
+# For every wml, update po |
|
63 |
+for file in $po ; do |
|
64 |
+ |
|
65 |
+ # Get the basename of the file we are dealing with |
|
66 |
+ pofile=`basename $file` |
|
67 |
+ |
|
68 |
+ # Strip the file for its original extension and the translation |
|
69 |
+ # priority, and add .wml |
|
70 |
+ wmlfile="`echo $pofile | cut -d . -f 2`.wml" |
|
71 |
+ |
|
72 |
+ # Find out what directory the file is in. |
|
73 |
+ indir=`dirname $file` |
|
74 |
+ |
|
75 |
+ # We also need to know what one directory up is |
|
76 |
+ onedirup=`dirname $indir` |
|
77 |
+ |
|
78 |
+ # We need to find out what subdirectory we are in |
|
79 |
+ subdir=`dirname $file | sed "s#$onedirup/##"` |
|
80 |
+ |
|
81 |
+ # And which language we are dealing with |
|
82 |
+ lang=`dirname $indir | sed "s#$podir/##"` |
|
83 |
+ |
|
84 |
+ # Time to write the translated wml file. |
|
85 |
+ # The translated document is written if 80% or more of the po |
|
86 |
+ # file has been translated. |
|
87 |
+ # Example: Use '-k 21' to set this number down to 21%. |
|
88 |
+ |
|
89 |
+ # The nice thing with po4a-translate is that it will only write |
|
90 |
+ # the translated document if 80% or more has been translated. |
|
91 |
+ # But it will delete the wml if less than 80% has been |
|
92 |
+ # translated. To avoid having our current, translated wml files |
|
93 |
+ # deleted, we first convert the po to a temp wml. If this file |
|
94 |
+ # was written, we'll rename it. |
|
95 |
+ |
|
96 |
+ # If $onedirup is equal to $lang, that means we do not have a |
|
97 |
+ # subdirectory. Also, we don't want to convert english po back |
|
98 |
+ # to english wml. |
|
99 |
+ if [ $onedirup == $lang ] |
|
100 |
+ then |
|
101 |
+ # The location of the english wml file |
|
102 |
+ english="$wmldir/en/$wmlfile" |
|
103 |
+ |
|
104 |
+ # Convert everything but the english po files |
|
105 |
+ if [ $subdir != "en" ] |
|
106 |
+ then |
|
107 |
+ po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault" |
|
108 |
+ |
|
109 |
+ # Check to see if the file was written |
|
110 |
+ if [ -e "$wmldir/$subdir/tmp-$wmlfile" ] |
|
111 |
+ then |
|
112 |
+ mv "$wmldir/$subdir/tmp-$wmlfile" "$wmldir/$subdir/$wmlfile" |
|
113 |
+ fi |
|
114 |
+ fi |
|
115 |
+ else |
|
116 |
+ # The location of the english wml file |
|
117 |
+ english="$wmldir/$subdir/en/$wmlfile" |
|
118 |
+ |
|
119 |
+ # Convert everything but the english po files |
|
120 |
+ if [ $lang != "en" ] |
|
121 |
+ then |
|
122 |
+ po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/$lang/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault" |
|
123 |
+ |
|
124 |
+ # Check to see if the file was written |
|
125 |
+ if [ -e "$wmldir/$subdir/$lang/tmp-$wmlfile" ] |
|
126 |
+ then |
|
127 |
+ mv "$wmldir/$subdir/$lang/tmp-$wmlfile" "$wmldir/$subdir/$lang/$wmlfile" |
|
128 |
+ fi |
|
129 |
+ fi |
|
130 |
+ fi |
|
131 |
+done |
... | ... |
@@ -0,0 +1,246 @@ |
1 |
+#!/bin/bash |
|
2 |
+# |
|
3 |
+# Author: Runa Sandvik, <runa.sandvik@gmail.com> |
|
4 |
+# Google Summer of Code 2009 |
|
5 |
+# |
|
6 |
+# This is Free Software (GPLv3) |
|
7 |
+# http://www.gnu.org/licenses/gpl-3.0.txt |
|
8 |
+# |
|
9 |
+# This script will convert all of the english wml files to pot files and |
|
10 |
+# keep them updated. |
|
11 |
+# |
|
12 |
+# For more information, see the HOWTO and README in |
|
13 |
+# translation/tools/gsoc09. |
|
14 |
+# |
|
15 |
+ |
|
16 |
+### start config ### |
|
17 |
+ |
|
18 |
+# Location of the wml files |
|
19 |
+wmldir="$PWD" |
|
20 |
+ |
|
21 |
+# Location of the pot files. |
|
22 |
+# Assuming that the translation directory is relative to the website |
|
23 |
+podir="`dirname $wmldir`/translation/projects/website/templates" |
|
24 |
+ |
|
25 |
+# Set the copyright holder of the pot files, |
|
26 |
+# for example "The Tor Project, Inc" |
|
27 |
+copyright="The Tor Project, Inc" |
|
28 |
+ |
|
29 |
+# A lot of the wml files have custom tags. These tags have been defined |
|
30 |
+# in website/include/versions.wmi. Tags that people usually forget to close, |
|
31 |
+# as well as tags that are not defined in versions.wmi have been added. |
|
32 |
+# See: https://svn.torproject.org/svn/website/trunk/include/versions.wmi |
|
33 |
+customtag=`echo $(cat "$wmldir/include/versions.wmi" | awk '{ printf "<%s> " , $2 }' | sed 's/<>//g') "<svnsandbox> <svnwebsite> <input> <hr> <br> <img>"` |
|
34 |
+ |
|
35 |
+# We also need to use the nodefault option of po4a; space separated list |
|
36 |
+# of tags that the module should not try to set by default in any |
|
37 |
+# category. For now, we only need the input tag. |
|
38 |
+nodefault='<input>' |
|
39 |
+ |
|
40 |
+# The script can write the name of unprocessed files to a log. |
|
41 |
+# If you want to enable this option, set the logfile here. |
|
42 |
+logfile="" |
|
43 |
+ |
|
44 |
+# This is the temp logfile. Leave this line even if you don't want to |
|
45 |
+# log. This will be deleted when the script is done. |
|
46 |
+tmplog="`dirname $wmldir`/tmp.log" |
|
47 |
+ |
|
48 |
+### end config ### |
|
49 |
+ |
|
50 |
+# Create a lockfile to make sure that only one instance of the script |
|
51 |
+# can run at any time. |
|
52 |
+LOCKFILE=wml2po.lock |
|
53 |
+ |
|
54 |
+if lockfile -! -l 60 -r 3 "$LOCKFILE"; |
|
55 |
+then |
|
56 |
+ echo "unable to acquire lock" >2 |
|
57 |
+ exit 1 |
|
58 |
+fi |
|
59 |
+ |
|
60 |
+trap "rm -f '$PWD/$LOCKFILE'" exit |
|
61 |
+ |
|
62 |
+# Check if translation/projects/website exist, i.e. has been checked out |
|
63 |
+if [ ! -d $podir ] |
|
64 |
+then |
|
65 |
+ echo "Have you remembered to check out translation/projects/website?" |
|
66 |
+ exit 1 |
|
67 |
+fi |
|
68 |
+ |
|
69 |
+# If the logfile is set, write the date. |
|
70 |
+if [ $logfile ] |
|
71 |
+then |
|
72 |
+ echo `date` > $logfile |
|
73 |
+fi |
|
74 |
+ |
|
75 |
+# Create the temp log |
|
76 |
+touch $tmplog |
|
77 |
+ |
|
78 |
+# cd to the right directory so we can commit the files later |
|
79 |
+cd "$podir" |
|
80 |
+ |
|
81 |
+# We only need the english wml files, but we do not wish to translate |
|
82 |
+# the eff documents. |
|
83 |
+wml=`find $wmldir -regex '^'$wmldir'/.*en/.*\.wml' -type f | grep -v '^'$wmldir'/eff'` |
|
84 |
+ |
|
85 |
+# For every wml, update po |
|
86 |
+for file in $wml ; do |
|
87 |
+ |
|
88 |
+ # Get the basename of the file we are dealing with |
|
89 |
+ wmlfile=`basename $file` |
|
90 |
+ |
|
91 |
+ # Get the translation priority |
|
92 |
+ priority=`cat $file | grep "# Translation-Priority" | awk '{print $3}'` |
|
93 |
+ |
|
94 |
+ # If the file doesn't have a translation-priority, we can assume |
|
95 |
+ # that it doesn't need to be translated. Skip this file and |
|
96 |
+ # continue on with the next. |
|
97 |
+ if [ ! $priority ] |
|
98 |
+ then |
|
99 |
+ continue |
|
100 |
+ fi |
|
101 |
+ |
|
102 |
+ # Strip the file for its original extension and add .pot |
|
103 |
+ pofile="$priority.${wmlfile%%.*}.pot" |
|
104 |
+ |
|
105 |
+ # Find out what directory the file is in. |
|
106 |
+ # Also, remove the parth of the path that is $wmldir |
|
107 |
+ indir=`dirname $file` |
|
108 |
+ |
|
109 |
+ # We need to know what one dir up is |
|
110 |
+ onedirup=`dirname $indir | sed "s#$wmldir/##"` |
|
111 |
+ |
|
112 |
+ # We need to have the correct, full path to the pot |
|
113 |
+ # directory for the file we are working on. |
|
114 |
+ # Also, did the subdirectory exist prior to running this |
|
115 |
+ # script? If not, create it now and add it to the |
|
116 |
+ # repository. |
|
117 |
+ if [ $onedirup = $wmldir ] |
|
118 |
+ then |
|
119 |
+ popath="$podir/$dir" |
|
120 |
+ |
|
121 |
+ # Check if the directory exists. If it doesn't, |
|
122 |
+ # create it |
|
123 |
+ if [ ! -d "$podir/$dir" ] |
|
124 |
+ then |
|
125 |
+ svn mkdir "$podir/$dir" |
|
126 |
+ fi |
|
127 |
+ else |
|
128 |
+ popath="$podir/$dir/$onedirup" |
|
129 |
+ |
|
130 |
+ # Check if the directory exists. If it doesn't, |
|
131 |
+ # create it. |
|
132 |
+ if [ ! -d "$podir/$dir/$onedirup" ] |
|
133 |
+ then |
|
134 |
+ svn mkdir "$podir/$dir/$onedirup" |
|
135 |
+ fi |
|
136 |
+ fi |
|
137 |
+ |
|
138 |
+ # Check to see if the pot file existed prior to running this |
|
139 |
+ # script. If it didn't, check if there any files with the same |
|
140 |
+ # filename, but different priority. If neither of the files |
|
141 |
+ # exist, create with po4a-gettextize. |
|
142 |
+ if [ -e "$popath/$pofile" ] |
|
143 |
+ then |
|
144 |
+ poexist=1 |
|
145 |
+ elif [ `find $popath -type f -name "*.$filename" | wc -l` -gt "0" ] |
|
146 |
+ then |
|
147 |
+ poexist=2 |
|
148 |
+ |
|
149 |
+ # We need to rename the other file |
|
150 |
+ for file in `find $popath -type f -name "*.$filename"` ; do |
|
151 |
+ svn mv "$file" "$popath/$pofile" |
|
152 |
+ echo "$popath/$pofile" > $tmplog |
|
153 |
+ done |
|
154 |
+ else |
|
155 |
+ poexist=0 |
|
156 |
+ fi |
|
157 |
+ |
|
158 |
+ # If the pot file does not exist, convert it with |
|
159 |
+ # po4a-gettextize, set the right encoding and charset |
|
160 |
+ # and the correct copyright. |
|
161 |
+ if [ $poexist = 0 ] |
|
162 |
+ then |
|
163 |
+ # Convert it |
|
164 |
+ po4a-gettextize -f wml -m "$file" -p "$popath/$pofile" --master-charset utf-8 -o customtag="$customtag" -o nodefault="$nodefault" |
|
165 |
+ |
|
166 |
+ # Check to see if the file exists |
|
167 |
+ if [ -e "$popath/$pofile" ] |
|
168 |
+ then |
|
169 |
+ # We don't want files without |
|
170 |
+ # content, so check the file first. |
|
171 |
+ content=`cat "$popath/$pofile" | grep '^#[.]' | wc -l` |
|
172 |
+ |
|
173 |
+ # If the file does not have any |
|
174 |
+ # content, delete it. |
|
175 |
+ if [ $content = 0 ] |
|
176 |
+ then |
|
177 |
+ rm -f "$popath/$pofile" |
|
178 |
+ echo "$popath/$pofile" > $tmplog |
|
179 |
+ else |
|
180 |
+ # Set the right encoding and charset, as well |
|
181 |
+ # as the correct copyright holder. |
|
182 |
+ sed -i '0,/ENCODING/ s/ENCODING/8bit/' "$popath/$pofile" |
|
183 |
+ sed -i '0,/CHARSET/ s/CHARSET/utf-8/' "$popath/$pofile" |
|
184 |
+ sed -i "0,/Free Software Foundation, Inc/ s/Free Software Foundation, Inc/$copyright/" "$popath/$pofile" |
|
185 |
+ |
|
186 |
+ # And add it to the repository |
|
187 |
+ svn add "$popath/$pofile" |
|
188 |
+ echo "$popath/$pofile" > $tmplog |
|
189 |
+ fi |
|
190 |
+ fi |
|
191 |
+ fi |
|
192 |
+ |
|
193 |
+ # If the pot file does exist, calculate the hash first, |
|
194 |
+ # then update the file, then calculate the hash again. |
|
195 |
+ if [ $poexist = 1 ] |
|
196 |
+ then |
|
197 |
+ # Calculate the hash before we update the file |
|
198 |
+ before=`grep -vE '^("POT-Creation-Date:|#)' "$popath/$pofile" | md5sum | cut -d " " -f1` |
|
199 |
+ |
|
200 |
+ # Update the pot file |
|
201 |
+ po4a-updatepo -f wml -m "$file" -p "$popath/$pofile" --master-charset utf-8 -o customtag="$customtag" -o nodefault="$nodefault" |
|
202 |
+ |
|
203 |
+ # Calculate the new hash |
|
204 |
+ after=`grep -vE '^("POT-Creation-Date:|#)' "$popath/$pofile" | md5sum | cut -d " " -f1` |
|
205 |
+ |
|
206 |
+ # Delete the backup |
|
207 |
+ rm -f "$popath/$pofile~" |
|
208 |
+ |
|
209 |
+ # Now we need to compare the before and after |
|
210 |
+ # hash. If they match (i.e. nothing has |
|
211 |
+ # changed), revert the file. |
|
212 |
+ if [ $before = $after ] |
|
213 |
+ then |
|
214 |
+ svn revert "$popath/$pofile" |
|
215 |
+ echo "$popath/$pofile" > $tmplog |
|
216 |
+ else |
|
217 |
+ echo "$popath/$pofile" > $tmplog |
|
218 |
+ fi |
|
219 |
+ fi |
|
220 |
+ |
|
221 |
+ # If a file with the same name but different priority |
|
222 |
+ # exist, then rename the file (we have done so already) |
|
223 |
+ # and update it with po4a-updatepo to make sure |
|
224 |
+ # everything else is ok. |
|
225 |
+ if [ $poexist = 2 ] |
|
226 |
+ then |
|
227 |
+ # Update the file |
|
228 |
+ po4a-updatepo -f wml -m "$file" -p "$popath/$pofile" --master-charset utf-8 -o customtag="$customtag" -o nodefault="$nodefault" |
|
229 |
+ fi |
|
230 |
+ |
|
231 |
+ # Write to the logfile |
|
232 |
+ if [ -e $logfile ] |
|
233 |
+ then |
|
234 |
+ if [ `cat $tmplog | grep "$popath/$pofile" | wc -l` -eq "0" ] |
|
235 |
+ then |
|
236 |
+ echo "could not process: " "$file" >> $logfile |
|
237 |
+ fi |
|
238 |
+ fi |
|
239 |
+ |
|
240 |
+ # Delete the temp log |
|
241 |
+ rm -f $tmplog |
|
242 |
+done |
|
243 |
+ |
|
244 |
+ # If you want the script to commit the files automatically, |
|
245 |
+ # uncomment the following line. |
|
246 |
+ # svn ci -m 'automatically generated and updated the pot files' |
|
0 | 247 |