318bb1212ff584f40f1f32d5d67a2950e65832e4
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 make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

120) 			# If the file is an Arabic translation, include
121) 			# the right header, css, menu files and footer
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

122) 			if [ $subdir = "ar" ]
123) 			then
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

124) 				# Head
125) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$wmlfile"`
126) 				temp_head=`echo $orig_head | sed s@head.wmi@ar/head.wmi@`
127) 				new_head=`echo $temp_head 'STYLESHEET="css/master-rtl.css"'`
128) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$wmlfile"
129) 
130) 				# Side (not all files include this)
131) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$wmlfile"`
132) 				if [ -n "$orig_side" ]
133) 				then
134) 					new_side=`echo '#include "ar/side.wmi"'`
135) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$wmlfile"
136) 				fi
137) 
138) 				# Info (not all files include this)
139) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$wmlfile"`
140) 				if [ -n "$orig_info" ]
141) 				then
142) 					new_info=`echo '#include "ar/info.wmi"'`
143) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$wmlfile"
144) 				fi
145) 
146) 				# Footer
147) 				echo '#include "ar/foot.wmi"' >> "$wmldir/$subdir/$wmlfile"
148) 			else
149) 				# Include the English footer
150) 				echo '#include "foot.wmi"' >> "$wmldir/$subdir/$wmlfile"
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

151) 			fi
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

152) 		fi
153) 	}	
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

154) 
Runa A. Sandvik do not keep old translations

Runa A. Sandvik authored 13 years ago

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

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

Runa A. Sandvik authored 14 years ago

160) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

163) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

176) 
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

177) 			# If the file is an Arabic translation, include the
178) 			# right header, css, menu files and footer
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

179) 			if [ $lang = "ar" ]
180) 			then
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

181) 				# Head
182) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
183) 				temp_head=`echo $orig_head | sed s@head.wmi@ar/head.wmi@`
184) 				new_head=`echo $temp_head 'STYLESHEET="css/master-rtl.css"'`
185) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$lang/$wmlfile"
186) 
187) 				# Side (not all files include this)
188) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
189) 				if [ -n "$orig_side" ]
190) 				then
191) 					new_side=`echo '#include "ar/side.wmi"'`
192) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$lang/$wmlfile"
193) 				fi
194) 
195) 				# Info (not all files include this)
196) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
197) 				if [ -n "$orig_info" ]
198) 				then
199) 					new_info=`echo '#include "ar/info.wmi"'`
200) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$lang/$wmlfile"
201) 				fi
202) 
203) 				# Footer
204) 				echo '#include "ar/foot.wmi"' >> "$wmldir/$subdir/$lang/$wmlfile"
205) 			else
206) 				# Include the English footer
207) 				echo '#include "foot.wmi"' >> "$wmldir/$subdir/$lang/$wmlfile"
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

208) 			fi
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

209) 		fi
210) 	}
211) 
212) 	# If $onedirup is equal to $lang, that means we do not have a
213) 	# subdirectory.
214) 	if [ $onedirup == $lang ]
215) 	then
216) 		# If the current subdirectory is "zh_CN" use "zh-cn" instead
217) 		if [ $subdir = "zh_CN" ]
218) 		then
219) 			subdir="zh-cn"
220) 			nosubdir
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

228) 		fi
229) 
230) 		# If the current directory is "sv" use "se" instead
231) 		if [ $subdir = "sv" ]
232) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

237) 		# If the current directory is "pl_PL" use "pl" instead
238) 		if [ $subdir = "pl_PL" ]
239) 		then
240) 			subdir="pl"
241) 			nosubdir
242) 		fi
243) 
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

244) 		# Convert everything else
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

246) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

248) 		fi
249) 	else
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

256) 
257) 		# If the current language is "nb" use "no" instead
258) 		if [ $lang = "nb" ]
259) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

262) 		fi
263) 
264) 		# If the current language is "sv" use "se" instead
265) 		if [ $lang = "sv" ]
266) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

270) 	
271) 		# If the current language is "pl_PL" use "pl" instead
272) 		if [ $lang = "pl_PL" ]
273) 		then
274) 			lang="pl"
275) 			subdir
276) 		fi
277) 
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

278) 		# Convert everything else
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

280) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

281) 			subdir