4e6637c71076f453ace6ab1779da03aba2bef2bf
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,
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
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
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) 
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

104) 		# If the current subdirectory is "zh_CN" use "zh-cn" instead
105) 		if [ $subdir = "zh_CN" ]
106) 		then
107) 			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/zh-cn/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/zh-cn/tmp-$wmlfile" ]
111) 			then
112) 				mv "$wmldir/zh-cn/tmp-$wmlfile" "$wmldir/zh-cn/$wmlfile"
Runa A. Sandvik remove last three lines of...

Runa A. Sandvik authored 14 years ago

113) 
114) 				# Remove last three lines in file
115) 				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/zh-cn/$wmlfile"
116) 
117) 				# Include foot.wmi
118) 				echo "#include <foot.wmi>" >> "$wmldir/zh-cn/$wmlfile"
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

119) 			fi
120) 		fi
121) 		
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

122) 		# If the current directory is "nb" use "no" instead
123) 		if [ $subdir = "nb" ]
124) 		then
125) 			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/no/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"	
126) 
127) 			# Check to see if the file was written
128) 			if [ -e "$wmldir/no/tmp-$wmlfile" ]
129) 			then
130) 				mv "$wmldir/no/tmp-$wmlfile" "$wmldir/no/$wmlfile"
Runa A. Sandvik remove last three lines of...

Runa A. Sandvik authored 14 years ago

131) 
132) 				# Remove last three lines in file
133) 				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/no/$wmlfile"
134) 
135) 				# Include foot.wmi
136) 				echo "#include <foot.wmi>" >> "$wmldir/no/$wmlfile"
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

137) 			fi
138) 		fi
139) 
140) 		# If the current directory is "sv" use "se" instead
141) 		if [ $subdir = "sv" ]
142) 		then
143) 			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/se/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
144) 
145) 			# Check to see if the file was written
146) 			if [ -e "$wmldir/se/tmp-$wmlfile" ]
147) 			then
148) 				mv "$wmldir/se/tmp-$wmlfile" "$wmldir/se/$wmlfile"
Runa A. Sandvik remove last three lines of...

Runa A. Sandvik authored 14 years ago

149) 
150) 				# Remove last three lines in file
151) 				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/se/$wmlfile"
152) 
153) 				# Include foot.wmi
154) 				echo "#include <foot.wmi>" >> "$wmldir/se/$wmlfile"
155) 
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

156) 			fi
157) 		fi
158) 
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

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

161) 		then
162) 			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"
163) 
164) 			# Check to see if the file was written
165) 			if [ -e "$wmldir/$subdir/tmp-$wmlfile" ]
166) 			then
167) 				mv "$wmldir/$subdir/tmp-$wmlfile" "$wmldir/$subdir/$wmlfile"
Runa A. Sandvik remove last three lines of...

Runa A. Sandvik authored 14 years ago

168) 
169) 				# Remove last three lines in file
170) 				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/$wmlfile"
171) 
172) 				# Include foot.wmi
173) 				echo "#include <foot.wmi>" >> "$wmldir/$subdir/$wmlfile"
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 14 years ago

174) 			fi
175) 		fi
176) 	else
177) 		# The location of the english wml file
178) 		english="$wmldir/$subdir/en/$wmlfile"
179) 		
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

180) 		# If the current language is "zh_CN" use "zh-cn" instead
181) 		if [ $lang = "zh_CN" ]
182) 		then
183) 			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/zh-cn/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
184) 
185) 			# Check to see if the file was written
186) 			if [ -e "$wmldir/$subdir/zh-cn/tmp-$wmlfile" ]
187) 			then
188) 				mv "$wmldir/$subdir/zh-cn/tmp-$wmlfile" "$wmldir/$subdir/zh-cn/$wmlfile"
Runa A. Sandvik remove last three lines of...

Runa A. Sandvik authored 14 years ago

189) 
190) 				# Remove last three lines in file
191) 				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/zh-cn/$wmlfile"
192) 
193) 				# Include foot.wmi
194) 				echo "#include <foot.wmi>" >> "$wmldir/$subdir/zh-cn/$wmlfile"
Runa A. Sandvik if the directory is zh_CN w...

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

197) 
198) 		# If the current language is "nb" use "no" instead
199) 		if [ $lang = "nb" ]
200) 		then
201) 			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/no/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
202) 
203) 			# Check to see if the file was written
204) 			if [ -e "$wmldir/$subdir/no/tmp-$wmlfile" ]
205) 			then
206) 				mv "$wmldir/$subdir/no/tmp-$wmlfile" "$wmldir/$subdir/no/$wmlfile"
Runa A. Sandvik remove last three lines of...

Runa A. Sandvik authored 14 years ago

207) 
208) 				# Remove last three lines in file
209) 				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/no/$wmlfile"
210) 
211) 				# Include foot.wmi
212) 				echo "#include <foot.wmi>" >> "$wmldir/$subdir/no/$wmlfile"
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

213) 			fi
214) 		fi
215) 
216) 		# If the current language is "sv" use "se" instead
217) 		if [ $lang = "sv" ]
218) 		then
219) 			po4a-translate -f wml -m "$english" -p "$file" -l "$wmldir/$subdir/se/tmp-$wmlfile" --master-charset utf-8 -L utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
220) 
221) 			# Check to see if the file was written
222) 			if [ -e "$wmldir/$subdir/se/tmp-$wmlfile" ]
223) 			then
224) 				mv "$wmldir/$subdir/se/tmp-$wmlfile" "$wmldir/$subdir/se/$wmlfile"
Runa A. Sandvik remove last three lines of...

Runa A. Sandvik authored 14 years ago

225) 
226) 				# Remove last three lines in file
227) 				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/se/$wmlfile"
228) 
229) 				# Include foot.wmi
230) 				echo "#include <foot.wmi>" >> "$wmldir/$subdir/se/$wmlfile"
Runa A. Sandvik quick fix for nb and sv

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

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

Runa A. Sandvik authored 14 years ago

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

236) 		then
237) 			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"
238) 
239) 			# Check to see if the file was written
240) 			if [ -e "$wmldir/$subdir/$lang/tmp-$wmlfile" ]
241) 			then
242) 				mv "$wmldir/$subdir/$lang/tmp-$wmlfile" "$wmldir/$subdir/$lang/$wmlfile"
Runa A. Sandvik remove last three lines of...

Runa A. Sandvik authored 14 years ago

243) 
244) 				# Remove last three lines in file
245) 				sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' "$wmldir/$subdir/$lang/$wmlfile"
246) 
247) 				# Include foot.wmi
248) 				echo "#include <foot.wmi>" >> "$wmldir/$subdir/$lang/$wmlfile"