e4c80226d40bd77ff116fae59a64a12833ba5917
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
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
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

86) 	# file has been translated. Example: Use '-k 21' to set this
87) 	# number down to 21%. Also, po4a-translate will only write the
88) 	# translated document if 80% or more has been translated.
89) 	# 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

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

93) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

99) 		# Convert the translated file. Note that po4a will write the file and then delete it if less than 80% has been translated
100) 		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

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

104) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

146) 			fi
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

147) 		fi
148) 	}	
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

149) 
Runa A. Sandvik do not keep old translations

Runa A. Sandvik authored 13 years ago

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

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

Runa A. Sandvik authored 14 years ago

155) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

158) 
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

161) 		then
162) 			# Remove last three lines in file
163) 			sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/$lang/$wmlfile"
164) 
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 13 years ago

169) 				# Head
170) 				orig_head=`grep '#include "head.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
171) 				temp_head=`echo $orig_head | sed s@head.wmi@ar/head.wmi@`
172) 				new_head=`echo $temp_head 'STYLESHEET="css/master-rtl.css"'`
173) 				sed -i "s@$orig_head@$new_head@" "$wmldir/$subdir/$lang/$wmlfile"
174) 
175) 				# Side (not all files include this)
176) 				orig_side=`grep '#include "side.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
177) 				if [ -n "$orig_side" ]
178) 				then
179) 					new_side=`echo '#include "ar/side.wmi"'`
180) 					sed -i "s@$orig_side@$new_side@" "$wmldir/$subdir/$lang/$wmlfile"
181) 				fi
182) 
183) 				# Info (not all files include this)
184) 				orig_info=`grep '#include "info.wmi"' "$wmldir/$subdir/$lang/$wmlfile"`
185) 				if [ -n "$orig_info" ]
186) 				then
187) 					new_info=`echo '#include "ar/info.wmi"'`
188) 					sed -i "s@$orig_info@$new_info@" "$wmldir/$subdir/$lang/$wmlfile"
189) 				fi
190) 
191) 				# Footer
192) 				echo '#include "ar/foot.wmi"' >> "$wmldir/$subdir/$lang/$wmlfile"
193) 			else
194) 				# Include the English footer
195) 				echo '#include "foot.wmi"' >> "$wmldir/$subdir/$lang/$wmlfile"
Runa A. Sandvik make sure arabic translatio...

Runa A. Sandvik authored 13 years ago

196) 			fi
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

197) 		fi
198) 	}
199) 
200) 	# If $onedirup is equal to $lang, that means we do not have a
201) 	# subdirectory.
202) 	if [ $onedirup == $lang ]
203) 	then
204) 		# If the current subdirectory is "zh_CN" use "zh-cn" instead
205) 		if [ $subdir = "zh_CN" ]
206) 		then
207) 			subdir="zh-cn"
208) 			nosubdir
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

216) 		fi
217) 
218) 		# If the current directory is "sv" use "se" instead
219) 		if [ $subdir = "sv" ]
220) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

223) 		fi
224) 
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

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

227) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

229) 		fi
230) 	else
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

237) 
238) 		# If the current language is "nb" use "no" instead
239) 		if [ $lang = "nb" ]
240) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

243) 		fi
244) 
245) 		# If the current language is "sv" use "se" instead
246) 		if [ $lang = "sv" ]
247) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

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

254) 		then
Runa A. Sandvik because functions are nice

Runa A. Sandvik authored 13 years ago

255) 			subdir