[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r19932: {} created a folder for this years GSoC and added the script wm (in translation/trunk/tools: . gsoc09)



Author: runa
Date: 2009-07-06 11:21:33 -0400 (Mon, 06 Jul 2009)
New Revision: 19932

Added:
   translation/trunk/tools/gsoc09/
   translation/trunk/tools/gsoc09/wml2po.sh
Log:
created a folder for this years GSoC and added the script wml2po

Added: translation/trunk/tools/gsoc09/wml2po.sh
===================================================================
--- translation/trunk/tools/gsoc09/wml2po.sh	                        (rev 0)
+++ translation/trunk/tools/gsoc09/wml2po.sh	2009-07-06 15:21:33 UTC (rev 19932)
@@ -0,0 +1,117 @@
+#!/bin/bash
+#
+# Author: Runa Sandvik, <runa.sandvik@xxxxxxxxx>
+# Google Summer of Code 2009
+#
+# This script will convert all of the english wml files to po files and
+# keep them updated.
+#
+
+### start config ###
+
+# Location of the wml files, 
+# for example "/home/runa/website/wml"
+wmldir=""
+
+# 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$`
+
+### end config ###
+
+# Create a lockfile to make sure that only one instance of the script
+# can run at any time.
+LOCKFILE=wml2po.lock
+
+if lockfile -! -l 60 -r 3 "$LOCKFILE"; 
+then
+	echo "unable to acquire lock" >2
+	exit 1
+fi
+
+trap "rm -f '$LOCKFILE'" exit
+
+# We only need the english wml files
+wml=`find $wmldir -regex '^'$wmldir'/.*en/.*\.wml' -type f`
+
+# For every wml, update po
+for file in $wml ; do
+	
+	# Get the basename of the file we are dealing with
+	wmlfile=`basename $file`
+
+	# Strip the file for its original extension and add .po
+	pofile="${wmlfile%%.*}.po"
+	
+	# Find out what directory the file is in
+	indir=`dirname $file`
+
+	# The path to the directory where the po files are
+	podir=`dirname $indir | sed 's/\<wml\>/po/'`
+
+	# Make sure the po file exist in every language directory
+	for dir in $lang ; do
+		
+		# We need to know if the po file exist before we run
+		# po4a-updatepo. If it doesn't, po4a-updatepo will
+		# create it.
+		if [ -e "$podir/$dir/$pofile" ]
+		then
+			poexist=1
+		else
+			poexist=0
+		fi
+		
+		# If the po file does exist, calculate the hash before
+		# the file is updated.	
+		if [ $poexist = 1 ]
+		then
+			before=`grep -v '^"POT-Creation-Date:'	"$podir/$dir/$pofile" | md5sum | cut -d " " -f1`
+		fi
+
+		# Update the file
+		po4a-updatepo -f wml -m "$file" -p "$podir/$dir/$pofile" --master-charset utf-8
+	
+		# Delete the backup
+		rm -f "$podir/$dir/$pofile~"
+	
+		# If the file existed before running po4a-updatepo,
+		# calculate the hash again.
+		if [ $poexist = 1 ]
+		then
+			after=`grep -v '^"POT-Creation-Date:' "$podir/$dir/$pofile" | md5sum | cut -d " " -f1`
+		fi
+		
+		# If the file did exist before running po4a-updatepo, we
+		# need to compare the before and after hash.
+		# If they match (i.e. nothing has changed), revert the
+		# file.
+		if [ $poexist = 1 ]
+		then
+			if [ $before = $after ]
+			then
+				svn revert "$podir/$dir/$pofile"
+			fi
+		fi
+		
+		# If the file did not exist before running
+		# po4a-updatepo but it does exist now, add the file to
+		# the repository and set the right encoding and charset.
+		if [ $poexist = 0 ]
+		then
+			if [ -e "$podir/$dir/$pofile" ]
+			then
+				# Add it to the repository
+				svn add "$podir/$onedirup/$dir/$pofile"
+
+				# And set the right encoding and charset
+				sed -i '1,/CHARSET/ s/CHARSET/UTF-8/' "$podir/$dir/$pofile"
+				sed -i '1,/ENCODING/ s/ENCODING/8bit/' "$podir/$dir/$pofile"
+			fi
+		fi
+	done
+
+	# Commit the files
+	svn ci -m 'automatically generated and updated the po files'
+done


Property changes on: translation/trunk/tools/gsoc09/wml2po.sh
___________________________________________________________________
Added: svn:executable
   + *