[or-cvs] r20203: {translation} convert to pot instead (translation/trunk/tools/gsoc09)

runa at seul.org runa at seul.org
Sun Aug 2 15:12:19 UTC 2009


Author: runa
Date: 2009-08-02 11:12:19 -0400 (Sun, 02 Aug 2009)
New Revision: 20203

Modified:
   translation/trunk/tools/gsoc09/wml2po.sh
Log:
convert to pot instead

Modified: translation/trunk/tools/gsoc09/wml2po.sh
===================================================================
--- translation/trunk/tools/gsoc09/wml2po.sh	2009-08-01 14:55:34 UTC (rev 20202)
+++ translation/trunk/tools/gsoc09/wml2po.sh	2009-08-02 15:12:19 UTC (rev 20203)
@@ -3,7 +3,7 @@
 # Author: Runa Sandvik, <runa.sandvik at gmail.com>
 # Google Summer of Code 2009
 #
-# This script will convert all of the english wml files to po files and
+# This script will convert all of the english wml files to pot files and
 # keep them updated.
 #
 
@@ -14,23 +14,19 @@
 # Note: do not put a slash at the end
 wmldir=""
 
-# Location of the po files,
-# for example "/home/runa/tor/translation/projects/website".
+# Location of the pot files (usually in the templates-folder),
+# for example "/home/runa/tor/translation/projects/website/templates".
 # Note: do not put a slash at the end
 podir=""
 
-# We need to know which languages directories we are dealing with.
-# We can either read a simple text file, or look at the language
-# directories in /var/lib/pootle/pootle
-lang=`ls "/var/lib/pootle/pootle" | grep -v ^templates$`
-
-# Set the copyright holder of the po files,
+# Set the copyright holder of the pot files,
 # for example "The Tor Project, Inc"
 copyright=""
 
 # A lot of the wml files have custom tags. These tags have been defined
 # in website/include/versions.wmi. Tags that people usually forget to close,
 # as well as tags that are not defined in versions.wmi have been added.
+# See: https://svn.torproject.org/svn/website/trunk/include/versions.wmi
 customtag=`echo $(cat "$wmldir/include/versions.wmi" | awk '{ printf "<%s> " , $2 }' | sed 's/<>//g') "<svnsandbox> <svnwebsite> <input> <hr> <br> <img>"`
 
 # We also need to use the nodefault option of po4a; space separated list
@@ -65,9 +61,6 @@
 	# Get the basename of the file we are dealing with
 	wmlfile=`basename $file`
 
-	# Strip the file for its original extension and add .po
-	filename="${wmlfile%%.*}.po"
-
 	# Get the translation priority
 	priority=`cat $file | grep "# Translation-Priority" | awk '{print $3}'`
 
@@ -79,8 +72,8 @@
 		continue
 	fi
 
-	# Strip the file for its original extension and add .po
-	pofile="$priority.${wmlfile%%.*}.po"
+	# Strip the file for its original extension and add .pot
+	pofile="$priority.${wmlfile%%.*}.pot"
 
 	# Find out what directory the file is in.
 	# Also, remove the parth of the path that is $wmldir
@@ -89,122 +82,117 @@
 	# We need to know what one dir up is
 	onedirup=`dirname $indir | sed "s#$wmldir/##"`
 
-	# Make sure the po file exist in every language directory
-	for dir in $lang ; do
+	# We need to have the correct, full path to the pot
+	# directory for the file we are working on.
+	# Also, did the subdirectory exist prior to running this
+	# script? If not, create it now and add it to the
+	# repository.
+	if [ $onedirup = $wmldir ]
+	then
+		popath="$podir/$dir"
 
-		# We need to have the correct, full path to the po
-		# directory for the file we are working on.
-		# Also, did the subdirectory exist prior to running this
-		# script? If not, create it now and add it to the
-		# repository.
-		if [ $onedirup = $wmldir ]
+		# Check if the directory exists. If it doesn't,
+		# create it
+		if [ ! -d "$podir/$dir" ]
 		then
-			popath="$podir/$dir"
+			svn mkdir "$podir/$dir"
+		fi
+	else
+		popath="$podir/$dir/$onedirup"
 
-			# Check if the directory exists. If it doesn't,
-			# create it
-			if [ ! -d "$podir/$dir" ]
-			then
-				svn mkdir "$podir/$dir"
-			fi
-		else
-			popath="$podir/$dir/$onedirup"
-
-			# Check if the directory exists. If it doesn't,
-			# create it.
-			if [ ! -d "$podir/$dir/$onedirup" ]
-			then
-				svn mkdir "$podir/$dir/$onedirup"
-			fi
+		# Check if the directory exists. If it doesn't,
+		# create it.
+		if [ ! -d "$podir/$dir/$onedirup" ]
+		then
+			svn mkdir "$podir/$dir/$onedirup"
 		fi
+	fi
 		
-		# Check to see if the po file existed prior to running this
-		# script. If it didn't, check if there any files with the same
-		# filename, but different priority. If neither of the files
-		# exist, create with po4a-gettextize.
-		if [ -e "$popath/$pofile" ]
-		then
-			poexist=1
-		elif [ `find $popath -type f -name "*.$filename" | wc -l` -gt "0" ]
-		then
-			poexist=2
+	# Check to see if the pot file existed prior to running this
+	# script. If it didn't, check if there any files with the same
+	# filename, but different priority. If neither of the files
+	# exist, create with po4a-gettextize.
+	if [ -e "$popath/$pofile" ]
+	then
+		poexist=1
+	elif [ `find $popath -type f -name "*.$filename" | wc -l` -gt "0" ]
+	then
+		poexist=2
 
-			# We need to rename the other file
-			for file in `find $popath -type f -name "*.$filename"` ; do
-				svn mv "$file" "$popath/$pofile"
-			done
-		else
-			poexist=0
-		fi
+		# We need to rename the other file
+		for file in `find $popath -type f -name "*.$filename"` ; do
+			svn mv "$file" "$popath/$pofile"
+		done
+	else
+		poexist=0
+	fi
 
-		# If the po file does not exist, convert it with
-		# po4a-gettextize, set the right encoding and charset
-		# and the correct copyright.
-		if [ $poexist = 0 ]
+	# If the pot file does not exist, convert it with
+	# po4a-gettextize, set the right encoding and charset
+	# and the correct copyright.
+	if [ $poexist = 0 ]
+	then
+		# Convert it
+		po4a-gettextize -f wml -m "$file" -p "$popath/$pofile" --master-charset utf-8 -o customtag="$customtag" -o nodefault="$nodefault" --copyright-holder "$copyright"
+
+		# Check to see if the file exists
+		if [ -e "$popath/$pofile" ]
 		then
-			# Convert it
-			po4a-gettextize -f wml -m "$file" -p "$popath/$pofile" --master-charset utf-8 -o customtag="$customtag" -o nodefault="$nodefault" --copyright-holder "$copyright"
+			# We don't want files without
+			# content, so check the file first.
+			content=`cat "$popath/$pofile" | grep '^#[.]' | wc -l`
 
-			# Check to see if the file exists
-			if [ -e "$popath/$pofile" ]
+			# If the file does not have any
+			# content, delete it.
+			if [ $content = 0 ] 
 			then
-				
-				# We don't want po files without
-				# content, so check the file first.
-				content=`cat "$popath/$pofile" | grep '^#[.]' | wc -l`
+				rm -f "$popath/$pofile"
+			else
+				# Set the right encoding and charset
+				sed -i '0,/ENCODING/ s/ENCODING/8bit/' "$popath/$pofile"
+				sed -i '0,/CHARSET/ s/CHARSET/utf-8/' "$popath/$pofile"
 
-				# If the po file does not have any
-				# content, delete it.
-				if [ $content = 0 ] 
-				then
-					rm -f "$popath/$pofile"
-				else
-					# Set the right encoding and charset
-					sed -i '0,/ENCODING/ s/ENCODING/8bit/' "$popath/$pofile"
-					sed -i '0,/CHARSET/ s/CHARSET/utf-8/' "$popath/$pofile"
-
-					# And add it to the repository
-					svn add "$popath/$pofile"
-				fi
+				# And add it to the repository
+				svn add "$popath/$pofile"
 			fi
 		fi
+	fi
 		
-		# If the po file does exist, calculate the hash first,
-		# then update the file, then calculate the hash again.
-		if [ $poexist = 1 ]
-		then
-			# Calculate the hash before we update the file
-			before=`grep -vE '^("POT-Creation-Date:|#)' "$popath/$pofile" | md5sum | cut -d " " -f1`
+	# If the pot file does exist, calculate the hash first,
+	# then update the file, then calculate the hash again.
+	if [ $poexist = 1 ]
+	then
+		# Calculate the hash before we update the file
+		before=`grep -vE '^("POT-Creation-Date:|#)' "$popath/$pofile" | md5sum | cut -d " " -f1`
 
-			# Update the po file
-			po4a-updatepo -f wml -m "$file" -p "$popath/$pofile" --master-charset utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
+		# Update the pot file
+		po4a-updatepo -f wml -m "$file" -p "$popath/$pofile" --master-charset utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
 
-			# Calculate the new hash
-			after=`grep -vE '^("POT-Creation-Date:|#)' "$popath/$pofile" | md5sum | cut -d " " -f1`
+		# Calculate the new hash
+		after=`grep -vE '^("POT-Creation-Date:|#)' "$popath/$pofile" | md5sum | cut -d " " -f1`
 
-			# Delete the backup
-			rm -f "$popath/$pofile~"
+		# Delete the backup
+		rm -f "$popath/$pofile~"
 
-			# Now we need to compare the before and after
-			# hash. If they match (i.e. nothing has
-			# changed), revert the file.
-			if [ $before = $after ]
-			then
-				svn revert "$popath/$pofile"
-			fi
-		fi
-
-		# If a file with the same name but different priority
-		# exist, then rename the file (we have done so already)
-		# and update it with po4a-updatepo to make sure
-		# everything else is ok.
-		if [ $poexist = 2 ]
+		# Now we need to compare the before and after
+		# hash. If they match (i.e. nothing has
+		# changed), revert the file.
+		if [ $before = $after ]
 		then
-			# Update the file
-			po4a-updatepo -f wml -m "$file" -p "$popath/$pofile" --master-charset utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
+			svn revert "$popath/$pofile"
 		fi
-	done
+	fi
 
+	# If a file with the same name but different priority
+	# exist, then rename the file (we have done so already)
+	# and update it with po4a-updatepo to make sure
+	# everything else is ok.
+	if [ $poexist = 2 ]
+	then
+		# Update the file
+		po4a-updatepo -f wml -m "$file" -p "$popath/$pofile" --master-charset utf-8 -o customtag="$customtag" -o nodefault="$nodefault"
+	fi
+
 	# Commit the files
 	svn ci -m 'automatically generated and updated the po files'
 done



More information about the tor-commits mailing list