ed6857826bc7f880b015c05b5616f83024259249
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 15 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 of the english wml files to pot files and
10) # keep them updated.
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 pot files.
22) # Assuming that the translation directory is relative to the website
23) podir="`dirname $wmldir`/translation/projects/website/templates"
24) 
25) # Set the copyright holder of the pot files,
26) # for example "The Tor Project, Inc"
27) copyright="The Tor Project, Inc"
28) 
29) # A lot of the wml files have custom tags. These tags have been defined
30) # in website/include/versions.wmi. Tags that people usually forget to close,
31) # as well as tags that are not defined in versions.wmi have been added.
32) # See: https://svn.torproject.org/svn/website/trunk/include/versions.wmi
33) customtag=`echo $(cat "$wmldir/include/versions.wmi" | awk '{ printf "<%s> " , $2 }' | sed 's/<>//g') "<svnsandbox> <svnwebsite> <input> <hr> <br> <img>"`
34) 
35) # We also need to use the nodefault option of po4a; space separated list
36) # of tags that the module should not try to set by default in any
37) # category. For now, we only need the input tag.
38) nodefault='<input>'
39) 
40) # The script can write the name of unprocessed files to a log.
41) # If you want to enable this option, set the logfile here.
42) logfile=""
43) 
44) # This is the temp logfile. Leave this line even if you don't want to
45) # log. This will be deleted when the script is done.
46) tmplog="`dirname $wmldir`/tmp.log"
47) 
48) ### end config ###
49) 
50) # Create a lockfile to make sure that only one instance of the script
51) # can run at any time.
52) LOCKFILE=wml2po.lock
53) 
54) if lockfile -! -l 60 -r 3 "$LOCKFILE"; 
55) then
56) 	echo "unable to acquire lock" >2
57) 	exit 1
58) fi
59) 
60) trap "rm -f '$PWD/$LOCKFILE'" exit
61) 
62) # Check if translation/projects/website exist, i.e. has been checked out
63) if [ ! -d $podir ]
64) then
65) 	echo "Have you remembered to check out translation/projects/website?"
66) 	exit 1
67) fi
68) 
69) # If the logfile is set, write the date.
70) if [ $logfile ]
71) then
72) 	echo `date` > $logfile
73) fi
74) 
75) # Create the temp log
76) touch $tmplog
77) 
78) # cd to the right directory so we can commit the files later
79) cd "$podir"
80) 
81) # We only need the english wml files, but we do not wish to translate
82) # the eff documents.
83) wml=`find $wmldir -regex '^'$wmldir'/.*en/.*\.wml' -type f | grep -v '^'$wmldir'/eff'`
84) 
85) # For every wml, update po
86) for file in $wml ; do
87) 
88) 	# Get the basename of the file we are dealing with
89) 	wmlfile=`basename $file`
90) 
91) 	# Get the translation priority
92) 	priority=`cat $file | grep "# Translation-Priority" | awk '{print $3}'`
93) 
94) 	# If the file doesn't have a translation-priority, we can assume
95) 	# that it doesn't need to be translated. Skip this file and
96) 	# continue on with the next.
97) 	if [ ! $priority ]
98) 	then
99) 		continue
100) 	fi
101) 
102) 	# Strip the file for its original extension and add .pot
103) 	pofile="$priority.${wmlfile%%.*}.pot"
104) 
105) 	# Find out what directory the file is in.
106) 	# Also, remove the parth of the path that is $wmldir
107) 	indir=`dirname $file`
108) 	
109) 	# We need to know what one dir up is
110) 	onedirup=`dirname $indir | sed "s#$wmldir/##"`
111) 
112) 	# We need to have the correct, full path to the pot
113) 	# directory for the file we are working on.
114) 	# Also, did the subdirectory exist prior to running this
115) 	# script? If not, create it now and add it to the
116) 	# repository.
117) 	if [ $onedirup = $wmldir ]
118) 	then
Runa A. Sandvik remove unused variable (aka...

Runa A. Sandvik authored 15 years ago

119) 		popath="$podir"
Runa A. Sandvik put the scripts in website

Runa A. Sandvik authored 15 years ago

120) 	else
Runa A. Sandvik if the subdirectory does no...

Runa A. Sandvik authored 15 years ago

121) 		# We need to know if a subdirectory, such as torbutton,
122) 		# exist in the translation module. If it does not exist,
123) 		# the script will create it in all the directories under
124) 		# translation/projects/website (excluding .svn)
125) 		langdir=`find $(dirname "$podir") -maxdepth 1 -type d ! -path $(dirname "$podir") ! -path "*\.*"`
126) 
127) 		for dir in $langdir ; do
128) 			if [ ! -d "$dir/$onedirup" ]
129) 			then
130) 				svn mkdir "$dir/$onedirup"
131) 			fi
132) 		done
133) 
134) 		# Set the path
Runa A. Sandvik remove unused variable (aka...

Runa A. Sandvik authored 15 years ago

135) 		popath="$podir/$onedirup"