4da8cf976f49a9bdc501c01e60577d821052e11b
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

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,
Runa A. Sandvik updated scripts with new path

Runa A. Sandvik authored 13 years ago

22) podir="`dirname $wmldir`/translation/projects/website/po"
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

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
Steven Murdoch Add a link tag for svnproje...

Steven Murdoch authored 14 years ago

28) customtag=`echo $(cat "$wmldir/include/versions.wmi" | awk '{ printf "<%s> " , $2 }' | sed 's/<>//g') "<svnsandbox> <svnwebsite> <svnprojects> <input> <hr> <br> <img> <gitblob>"`
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

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
Runa A. Sandvik call validate.py before con...

Runa A. Sandvik authored 13 years ago

64) 
65) 	# Validate input and write results to a log file
66) 	validate_script="`dirname $wmldir`/translation/tools/validate.py"
Runa A. Sandvik updated script and new tran...

Runa A. Sandvik authored 13 years ago

67) 	validate_log="`dirname $wmldir`/validate/website-validate.log"
Runa A. Sandvik call validate.py before con...

Runa A. Sandvik authored 13 years ago

68) 	python "$validate_script" -i "$file" -l	"$validate_log"
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

69) 	
70) 	# Get the basename of the file we are dealing with
71) 	pofile=`basename $file`
72) 
73) 	# Strip the file for its original extension and the translation
74) 	# priority, and add .wml
75) 	wmlfile="`echo $pofile | cut -d . -f 2`.wml"	
76) 
77) 	# Find out what directory the file is in.
78) 	indir=`dirname $file`
79) 
80) 	# We also need to know what one directory up is
81) 	onedirup=`dirname $indir`
82) 
83) 	# We need to find out what subdirectory we are in
84) 	subdir=`dirname $file | sed "s#$onedirup/##"`
85) 
86) 	# And which language we are dealing with
87) 	lang=`dirname $indir | sed "s#$podir/##"`
88) 
89) 	# Time to write the translated wml file.
90) 	# The translated document is written if 80% or more of the po
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

91) 	# file has been translated. Example: Use '-k 21' to set this
92) 	# number down to 21%. Also, po4a-translate will only write the
93) 	# translated document if 80% or more has been translated.
94) 	# However, it will delete the wml if less than 80% has been
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

95) 	# translated. To avoid having our current, translated wml files
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

96) 	# deleted, convert the po to a temp wml first. If this file was
97) 	# actually written, rename it to wml.
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

98) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

99) 	# Convert translations to directories such as website/nb/.
100) 	function nosubdir {
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

101) 		# The location of the english wml file
102) 		english="$wmldir/en/$wmlfile"
103) 
Runa A. Sandvik do not keep old translations

Runa A. Sandvik authored 13 years ago

104) 		# Convert the translated file. Note that po4a will write the file and then delete it if less than 80% has been translated
105) 		po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

106) 
107) 		# Check to see if the file was written
Runa A. Sandvik do not keep old translations

Runa A. Sandvik authored 13 years ago

108)                 if [ -e "$wmldir/$subdir/$wmlfile" ]
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

109) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

110)                         # Remove last three lines in file
111) 			sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/$wmlfile"
112) 
Runa A. Sandvik automatically fix mirrors.w...

Runa A. Sandvik authored 13 years ago

113) 			# If the file is mirrors.wml, include mirrors-table.wmi
114) 			if [ $wmlfile == "mirrors.wml" ]
115) 			then
116) 				sed -i 's/<!--PO4ASHARPBEGIN/#/' "$wmldir/$subdir/$wmlfile"
117) 				sed -i 's/PO4ASHARPEND-->//' "$wmldir/$subdir/$wmlfile"
118) 			fi
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

119) 
Runa A. Sandvik update po2wml to include Po...

Runa A. Sandvik authored 13 years ago

120) 			# Include the English footer for most of the
121) 			# translations
122) 			if [[ $subdir != "ar" && $subdir != "pl" ]]
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

123) 			then
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

124) 				echo '#include "foot.wmi"' >> "$wmldir/$subdir/$wmlfile"
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

125) 			fi
Runa A. Sandvik update po2wml to include Po...

Runa A. Sandvik authored 13 years ago

126) 
127) 			# If the directory does not include sidenav.wmi,
128) 			# copy it from the English directory (only if
129) 			# the English directory has this file)
130) 			if [[ ! -e "$wmldir/$subdir/sidenav.wmi" && -e "$wmldir/en/sidenav.wmi" ]]
131) 			then
132) 				cp "$wmldir/en/sidenav.wmi" "$wmldir/$subdir"
133) 			fi
134) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

135) 		fi
136) 	}	
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

137) 
Runa A. Sandvik do not keep old translations

Runa A. Sandvik authored 13 years ago

138) 	# Convert translations to directories such as website/torbrowser/nb/.
139) 	# Again, po4a will write the file and then delete it if less than 80% has been translated
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

140) 	function subdir {
141) 		# The location of the english wml file
142)                 english="$wmldir/$subdir/en/$wmlfile"
Runa A. Sandvik remove last three lines of...

Runa A. Sandvik authored 14 years ago

143) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

144) 		# Convert the files
Runa A. Sandvik do not keep old translations

Runa A. Sandvik authored 13 years ago

145) 		po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/$lang/$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
Runa A. Sandvik remove last three lines of...

Runa A. Sandvik authored 14 years ago

146) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

147) 		# Check to see if the file was written
Runa A. Sandvik do not keep old translations

Runa A. Sandvik authored 13 years ago

148) 		if [ -e "$wmldir/$subdir/$lang/$wmlfile" ]
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

149) 		then
150) 			# Remove last three lines in file
151) 			sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/$lang/$wmlfile"
152) 
Runa A. Sandvik updated translations for th...

Runa A. Sandvik authored 13 years ago

153) 			# Remove a specific comment from a specific file
154) 			if [ $wmlfile == "download-easy.wml" ]			
155) 			then
156) 				translator_comment="# Translators: please point to the version of TBB in your language, if there is one."
157) 				sed -i "s/$translator_comment//" "$wmldir/$subdir/$lang/$wmlfile"
158) 			fi
Runa A. Sandvik remove translator comments...

Runa A. Sandvik authored 13 years ago

159) 
Runa A. Sandvik update po2wml to include Po...

Runa A. Sandvik authored 13 years ago

160) 			# Include the English footer for most of the
161) 			# translations 
162) 			if [[ $lang != "ar" && $lang != "pl" ]]
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

163) 			then
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

164) 				echo '#include "foot.wmi"' >> "$wmldir/$subdir/$lang/$wmlfile"
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

165) 			fi
Runa A. Sandvik update po2wml to include Po...

Runa A. Sandvik authored 13 years ago

166) 
167) 			# If the directory does not include sidenav.wmi,
168) 			# copy it from the English directory (only if 
169) 			# the English directory has this file)
170) 			if [[ ! -e "$wmldir/$subdir/$lang/sidenav.wmi" && -e "$wmldir/$subdir/en/sidenav.wmi" ]]
171) 			then
172) 				cp "$wmldir/$subdir/en/sidenav.wmi" "$wmldir/$subdir/$lang/"
173) 			fi
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

174) 		fi
175) 	}
176) 
177) 	# If $onedirup is equal to $lang, that means we do not have a
178) 	# subdirectory.
179) 	if [ $onedirup == $lang ]
180) 	then
181) 		# If the current subdirectory is "zh_CN" use "zh-cn" instead
182) 		if [ $subdir = "zh_CN" ]
183) 		then
184) 			subdir="zh-cn"
185) 			nosubdir
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

186) 		fi
187) 		
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

188) 		# If the current directory is "nb" use "no" instead
189) 		if [ $subdir = "nb" ]
190) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

191) 			subdir="no"
192) 			nosubdir
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

193) 		fi
194) 
195) 		# If the current directory is "sv" use "se" instead
196) 		if [ $subdir = "sv" ]
197) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

198) 			subdir="se"
199) 			nosubdir
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

200) 		fi
201) 
Runa A. Sandvik we want to use pl instead o...

Runa A. Sandvik authored 13 years ago

202) 		# If the current directory is "pl_PL" use "pl" instead
203) 		if [ $subdir = "pl_PL" ]
204) 		then
205) 			subdir="pl"
206) 			nosubdir
Runa A. Sandvik update po2wml to include Po...

Runa A. Sandvik authored 13 years ago

207) 
208) 			# If the file was written, include the right
209) 			# header, menu files and footer
210) 			if [ -e "$wmldir/$subdir/$wmlfile" ]
211) 			then
212) 				# Head
213) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$wmlfile"`
214) 				new_head=`echo $orig_head | sed s@head.wmi@pl/head.wmi@`
215) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$wmlfile"
216) 
217) 				# Side (not all files include this)
218) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$wmlfile"`
219) 				if [ -n "$orig_side" ]
220) 				then
221) 					new_side=`echo '#include "pl/side.wmi"'`
222) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$wmlfile"
223) 				fi
224) 
225) 				# Info (not all files include this)
226) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$wmlfile"`
227) 				if [ -n "$orig_info" ]
228) 				then
229) 					new_info=`echo '#include "pl/info.wmi"'`
230) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$wmlfile"
231) 				fi
232) 
233) 				# Footer
234) 				echo '#include "pl/foot.wmi"' >> "$wmldir/$subdir/$wmlfile"
235) 			fi
236) 		fi
237) 
238) 		# If the file is an Arabic translation, include
239) 		# the right header, css, menu files and footer
240)                 if [ $subdir = "ar" ]
241) 		then
242) 			# Convert the file first
243) 			nosubdir
244) 
245) 			# If it was written, do the following
246) 			if [ -e "$wmldir/$subdir/$wmlfile" ]
247) 			then
248) 				# Head
249) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$wmlfile"`
250) 				temp_head=`echo $orig_head | sed s@head.wmi@ar/head.wmi@`
251) 				new_head=`echo $temp_head 'STYLESHEET="css/master-rtl.css"'`
252) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$wmlfile"
253) 
254) 				# Side (not all files include this)
255) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$wmlfile"`
256) 				if [ -n "$orig_side" ]
257) 				then
258) 					new_side=`echo '#include "ar/side.wmi"'`
259) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$wmlfile"
260) 				fi
261) 	
262) 				# Info (not all files include this)
263) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$wmlfile"`
264) 				if [ -n "$orig_info" ]
265) 				then
266) 					new_info=`echo '#include "ar/info.wmi"'`
267) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$wmlfile"
268) 				fi
269) 
270) 				# Footer
271) 				echo '#include "ar/foot.wmi"' >> "$wmldir/$subdir/$wmlfile"
272) 			fi
Runa A. Sandvik we want to use pl instead o...

Runa A. Sandvik authored 13 years ago

273) 		fi
274) 
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

275) 		# Convert everything else
Runa A. Sandvik update po2wml to include Po...

Runa A. Sandvik authored 13 years ago

276) 		if [[ $subdir != "en" && $subdir != "zh_CN" && $subdir != "nb" && $subdir != "sv" && $subdir != "ar" ]]
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

277) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

278) 			nosubdir
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

279) 		fi
280) 	else
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

281) 		# If the current language is "zh_CN" use "zh-cn" instead
282) 		if [ $lang = "zh_CN" ]
283) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

284) 			lang="zh-cn"
285) 			subdir
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

286) 		fi
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

287) 
288) 		# If the current language is "nb" use "no" instead
289) 		if [ $lang = "nb" ]
290) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

291) 			lang="no"
292) 			subdir
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

293) 		fi
294) 
295) 		# If the current language is "sv" use "se" instead
296) 		if [ $lang = "sv" ]
297) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

298) 			lang="se"
299) 			subdir
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

300) 		fi
Runa A. Sandvik we want to use pl instead o...

Runa A. Sandvik authored 13 years ago

301) 	
302) 		# If the current language is "pl_PL" use "pl" instead
303) 		if [ $lang = "pl_PL" ]
304) 		then
305) 			lang="pl"
306) 			subdir
Runa A. Sandvik update po2wml to include Po...

Runa A. Sandvik authored 13 years ago

307) 
308) 			# If the file was written, include the right
309) 			# header, menu files and footer
310) 			if [ -e "$wmldir/$subdir/$lang/$wmlfile" ]
311) 			then
312) 				# Head
313) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
314) 				new_head=`echo $orig_head | sed s@head.wmi@pl/head.wmi@`
315) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$lang/$wmlfile"
316) 
317) 				# Side (not all files include this)
318) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
319) 				if [ -n "$orig_side" ]
320) 				then
321) 					new_side=`echo '#include "pl/side.wmi"'`
322) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$lang/$wmlfile"
323) 				fi
324) 
325) 				# Info (not all files include this)
326) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
327) 				if [ -n "$orig_info" ]
328) 				then
329) 					new_info=`echo '#include "pl/info.wmi"'`
330) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$lang/$wmlfile"
331) 				fi
332) 
333) 				# Footer
334) 				echo '#include "pl/foot.wmi"' >> "$wmldir/$subdir/$lang/$wmlfile"
335) 			fi
336) 
337) 		fi
338) 
339) 		# If the file is an Arabic translation, include the
340) 		# right header, css, menu files and footer
341) 		if [ $lang = "ar" ]
342) 		then
343) 			# Convert the file first
344) 			subdir
345) 
346) 			# If it was written, do the following
347) 			if [ -e "$wmldir/$subdir/$lang/$wmlfile" ]
348) 			then
349) 				# Head
350) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
351) 				temp_head=`echo $orig_head | sed s@head.wmi@ar/head.wmi@`
352) 				new_head=`echo $temp_head 'STYLESHEET="css/master-rtl.css"'`
353) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$lang/$wmlfile"
354) 
355) 				# Side (not all files include this)
356) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
357) 				if [ -n "$orig_side" ]
358) 				then
359) 					new_side=`echo '#include "ar/side.wmi"'`
360) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$lang/$wmlfile"
361) 				fi
362) 
363) 				# Info (not all files include this)
364) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
365) 				if [ -n "$orig_info" ]
366) 				then
367) 					new_info=`echo '#include "ar/info.wmi"'`
368) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$lang/$wmlfile"
369) 				fi
370) 
371) 				# Footer
372) 				echo '#include "ar/foot.wmi"' >> "$wmldir/$subdir/$lang/$wmlfile"
373) 			fi
Runa A. Sandvik we want to use pl instead o...

Runa A. Sandvik authored 13 years ago

374) 		fi
375) 
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

376) 		# Convert everything else
Runa A. Sandvik update po2wml to include Po...

Runa A. Sandvik authored 13 years ago

377) 		if [[ $lang != "en" && $lang != "zh_CN" && $lang != "nb" && $lang != "sv" && $lang != "ar" ]]
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

378) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

379) 			subdir