29f41ca6d9dab1d5f5b4cefa633133477c327d14
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) 
Runa A. Sandvik update po2wml to make thing...

Runa A. Sandvik authored 13 years ago

127) 			# If the translation is Polish, include the
128) 			# correct header, menu files and footer
129) 			if [ $subdir = "pl" ]
130) 			then
131) 				# Head
132) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$wmlfile"`
133) 				new_head=`echo $orig_head | sed s@head.wmi@pl/head.wmi@`
134) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$wmlfile"
135) 
136) 				# Side (not all files include this)
137) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$wmlfile"`
138) 				if [ -n "$orig_side" ]
139) 				then
140) 					new_side=`echo '#include "pl/side.wmi"'`
141) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$wmlfile"
142) 				fi
143) 
144) 				# Info (not all files include this)
145) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$wmlfile"`
146) 				if [ -n "$orig_info" ]
147) 				then
148) 					new_info=`echo '#include "pl/info.wmi"'`
149) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$wmlfile"
150) 				fi
151) 
152) 				# Footer
153) 				echo '#include "pl/foot.wmi"' >> "$wmldir/$subdir/$wmlfile"
154) 			fi
155) 
156) 			# If the translation is Arabic, include the
157) 			# correct header, css, menu files and footer
158) 			if [ $subdir = "ar" ]
159) 			then
160) 				# Head
161) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$wmlfile"`
162) 				temp_head=`echo $orig_head | sed s@head.wmi@ar/head.wmi@`
163) 				new_head=`echo $temp_head 'STYLESHEET="css/master-rtl.css"'`
164) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$wmlfile"
165) 
166) 				# Side (not all files include this)
167) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$wmlfile"`
168) 				if [ -n "$orig_side" ]
169) 				then
170) 					new_side=`echo '#include "ar/side.wmi"'`
171) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$wmlfile"
172) 				fi
173) 
174) 				# Info (not all files include this)
175) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$wmlfile"`
176) 				if [ -n "$orig_info" ]
177) 				then
178) 					new_info=`echo '#include "ar/info.wmi"'`
179) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$wmlfile"
180) 				fi
181) 
182) 				# Footer
183) 				echo '#include "ar/foot.wmi"' >> "$wmldir/$subdir/$wmlfile"
184) 			fi
185) 
Runa A. Sandvik update po2wml to include Po...

Runa A. Sandvik authored 13 years ago

186) 			# If the directory does not include sidenav.wmi,
187) 			# copy it from the English directory (only if
188) 			# the English directory has this file)
189) 			if [[ ! -e "$wmldir/$subdir/sidenav.wmi" && -e "$wmldir/en/sidenav.wmi" ]]
190) 			then
191) 				cp "$wmldir/en/sidenav.wmi" "$wmldir/$subdir"
192) 			fi
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

193) 		fi
194) 	}	
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

195) 
Runa A. Sandvik do not keep old translations

Runa A. Sandvik authored 13 years ago

196) 	# Convert translations to directories such as website/torbrowser/nb/.
197) 	# 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

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

Runa A. Sandvik authored 14 years ago

201) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

203) 		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

204) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

224) 
Runa A. Sandvik update po2wml to make thing...

Runa A. Sandvik authored 13 years ago

225)                         # If the translation is Polish, include the
226)                         # correct header, menu files and footer
227) 			if [ $lang = "pl" ]
228) 			then
229) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
230) 				new_head=`echo $orig_head | sed s@head.wmi@pl/head.wmi@`
231) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$lang/$wmlfile"
232) 
233) 				# Side (not all files include this)
234) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
235) 				if [ -n "$orig_side" ]
236) 				then
237) 					new_side=`echo '#include "pl/side.wmi"'`
238) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$lang/$wmlfile"
239) 				fi
240) 
241) 				# Info (not all files include this)
242) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
243) 				if [ -n "$orig_info" ]
244) 				then
245) 					new_info=`echo '#include "pl/info.wmi"'`
246) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$lang/$wmlfile"
247) 				fi
248) 
249) 				# Footer
250) 				echo '#include "pl/foot.wmi"' >> "$wmldir/$subdir/$lang/$wmlfile"
251) 			fi
252) 
253) 			# If the file is an Arabic translation, include the
254) 			# correct header, css, menu files and footer
255) 			if [ $lang = "ar" ]
256) 			then
257) 				# Head
258) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
259) 				temp_head=`echo $orig_head | sed s@head.wmi@ar/head.wmi@`
260) 				new_head=`echo $temp_head 'STYLESHEET="css/master-rtl.css"'`
261) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$lang/$wmlfile"
262) 
263) 				# Side (not all files include this)
264) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
265) 				if [ -n "$orig_side" ]
266) 				then
267) 					new_side=`echo '#include "ar/side.wmi"'`
268) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$lang/$wmlfile"
269) 				fi
270) 
271) 				# Info (not all files include this)
272) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
273) 				if [ -n "$orig_info" ]
274) 				then
275) 					new_info=`echo '#include "ar/info.wmi"'`
276) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$lang/$wmlfile"
277) 				fi
278) 
279) 				# Footer
280) 				echo '#include "ar/foot.wmi"' >> "$wmldir/$subdir/$lang/$wmlfile"
281) 			fi
282) 
Runa A. Sandvik update po2wml to include Po...

Runa A. Sandvik authored 13 years ago

283) 			# If the directory does not include sidenav.wmi,
284) 			# copy it from the English directory (only if 
285) 			# the English directory has this file)
286) 			if [[ ! -e "$wmldir/$subdir/$lang/sidenav.wmi" && -e "$wmldir/$subdir/en/sidenav.wmi" ]]
287) 			then
288) 				cp "$wmldir/$subdir/en/sidenav.wmi" "$wmldir/$subdir/$lang/"
289) 			fi
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

290) 		fi
291) 	}
292) 
293) 	# If $onedirup is equal to $lang, that means we do not have a
294) 	# subdirectory.
295) 	if [ $onedirup == $lang ]
296) 	then
297) 		# If the current subdirectory is "zh_CN" use "zh-cn" instead
298) 		if [ $subdir = "zh_CN" ]
299) 		then
300) 			subdir="zh-cn"
301) 			nosubdir
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

309) 		fi
310) 
311) 		# If the current directory is "sv" use "se" instead
312) 		if [ $subdir = "sv" ]
313) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

318) 		# If the current directory is "pl_PL" use "pl" instead
319) 		if [ $subdir = "pl_PL" ]
320) 		then
321) 			subdir="pl"
322) 			nosubdir
323) 		fi
324) 
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

325) 		# Convert everything else
Runa A. Sandvik update po2wml to make thing...

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

327) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

329) 		fi
330) 	else
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

337) 
338) 		# If the current language is "nb" use "no" instead
339) 		if [ $lang = "nb" ]
340) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

343) 		fi
344) 
345) 		# If the current language is "sv" use "se" instead
346) 		if [ $lang = "sv" ]
347) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

351) 	
352) 		# If the current language is "pl_PL" use "pl" instead
353) 		if [ $lang = "pl_PL" ]
354) 		then
355) 			lang="pl"
356) 			subdir
357) 		fi
358) 
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

359) 		# Convert everything else
Runa A. Sandvik update po2wml to make thing...

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

361) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

362) 			subdir