2009-08-16 08:11:41 +00:00
#!/bin/bash
#
# Author: Runa Sandvik, <runa.sandvik@gmail.com>
# Google Summer of Code 2009
#
# This is Free Software (GPLv3)
# http://www.gnu.org/licenses/gpl-3.0.txt
#
# This script will convert all the translated po files back to wml
# files.
#
# For more information, see the HOWTO and README in
# translation/tools/gsoc09.
#
### start config ###
# Location of the wml files
wmldir = " $PWD "
# Location of the po files,
2010-09-19 12:11:39 +00:00
podir = " `dirname $wmldir `/translation/projects/website/po "
2009-08-16 08:11:41 +00:00
# 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
2010-03-25 15:02:01 +00:00
customtag = ` echo $( cat " $wmldir /include/versions.wmi " | awk '{ printf "<%s> " , $2 }' | sed 's/<>//g' ) "<svnsandbox> <svnwebsite> <svnprojects> <input> <hr> <br> <img> <gitblob>" `
2009-08-16 08:11:41 +00:00
# We also need to use the nodefault option of po4a; space separated list
# of tags that the module should not try to set by default in any
# category. For now, we only need the input tag.
nodefault = '<input>'
### end config ###
# Create a lockfile to make sure that only one instance of the script
# can run at any time.
LOCKFILE = po2wml.lock
if lockfile -! -l 60 -r 3 " $LOCKFILE " ;
then
echo "unable to acquire lock" >2
exit 1
fi
trap " rm -f ' $PWD / $LOCKFILE ' " exit
# Check if translation/projects/website exist, i.e. has been checked out
if [ ! -d $podir ]
then
echo "Have you remembered to check out translation/projects/website?"
exit 1
fi
# cd to the right directory so we can commit the files later
cd " $wmldir "
# We need to find the po files
po = ` find $podir -regex '^' $podir '/.*/.*\.po' -type f`
# For every wml, update po
for file in $po ; do
2011-03-17 17:35:47 +00:00
# Validate input and write results to a log file
validate_script = " `dirname $wmldir `/translation/tools/validate.py "
2011-03-18 15:39:36 +00:00
validate_log = " `dirname $wmldir `/validate/website-validate.log "
2011-03-17 17:35:47 +00:00
python " $validate_script " -i " $file " -l " $validate_log "
2009-08-16 08:11:41 +00:00
# Get the basename of the file we are dealing with
pofile = ` basename $file `
# Strip the file for its original extension and the translation
# priority, and add .wml
wmlfile = " `echo $pofile | cut -d . -f 2`.wml "
# Find out what directory the file is in.
indir = ` dirname $file `
# We also need to know what one directory up is
onedirup = ` dirname $indir `
# We need to find out what subdirectory we are in
subdir = ` dirname $file | sed " s# $onedirup /## " `
# And which language we are dealing with
lang = ` dirname $indir | sed " s# $podir /## " `
# Time to write the translated wml file.
# The translated document is written if 80% or more of the po
2010-05-16 10:35:06 +00:00
# file has been translated. Example: Use '-k 21' to set this
# number down to 21%. Also, po4a-translate will only write the
# translated document if 80% or more has been translated.
# However, it will delete the wml if less than 80% has been
2009-08-16 08:11:41 +00:00
# translated. To avoid having our current, translated wml files
2010-05-16 10:35:06 +00:00
# deleted, convert the po to a temp wml first. If this file was
# actually written, rename it to wml.
2009-08-16 08:11:41 +00:00
2010-05-16 10:35:06 +00:00
# Convert translations to directories such as website/nb/.
function nosubdir {
2009-08-16 08:11:41 +00:00
# The location of the english wml file
english = " $wmldir /en/ $wmlfile "
2010-08-18 19:27:29 +00:00
# Convert the translated file. Note that po4a will write the file and then delete it if less than 80% has been translated
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 "
2010-05-16 10:35:06 +00:00
# Check to see if the file was written
2010-08-18 19:27:29 +00:00
if [ -e " $wmldir / $subdir / $wmlfile " ]
2009-12-13 19:49:01 +00:00
then
2010-05-16 10:35:06 +00:00
# Remove last three lines in file
sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' " $wmldir / $subdir / $wmlfile "
2010-09-04 21:08:37 +00:00
# If the file is mirrors.wml, include mirrors-table.wmi
if [ $wmlfile = = "mirrors.wml" ]
then
sed -i 's/<!--PO4ASHARPBEGIN/#/' " $wmldir / $subdir / $wmlfile "
sed -i 's/PO4ASHARPEND-->//' " $wmldir / $subdir / $wmlfile "
fi
2011-03-17 08:53:43 +00:00
2011-03-30 14:08:39 +00:00
# Include the English footer for most of the
# translations
2011-04-11 14:50:21 +00:00
if [ [ $subdir != "ar" && $subdir != "pl" && $subdir != "de" ] ]
2011-03-17 08:53:43 +00:00
then
2011-03-17 12:31:41 +00:00
echo '#include "foot.wmi"' >> " $wmldir / $subdir / $wmlfile "
2011-03-17 08:53:43 +00:00
fi
2011-03-30 14:08:39 +00:00
2011-03-31 11:17:24 +00:00
# If the translation is Polish, include the
# correct header, menu files and footer
if [ $subdir = "pl" ]
then
# Head
orig_head = ` grep '#include "head.wmi"' " $wmldir / $subdir / $wmlfile " `
new_head = ` echo $orig_head | sed s@head.wmi@pl/head.wmi@`
sed -i " s@ $orig_head @ $new_head @ " " $wmldir / $subdir / $wmlfile "
# Side (not all files include this)
orig_side = ` grep '#include "side.wmi"' " $wmldir / $subdir / $wmlfile " `
if [ -n " $orig_side " ]
then
new_side = ` echo '#include "pl/side.wmi"' `
sed -i " s@ $orig_side @ $new_side @ " " $wmldir / $subdir / $wmlfile "
fi
# Info (not all files include this)
orig_info = ` grep '#include "info.wmi"' " $wmldir / $subdir / $wmlfile " `
if [ -n " $orig_info " ]
then
new_info = ` echo '#include "pl/info.wmi"' `
sed -i " s@ $orig_info @ $new_info @ " " $wmldir / $subdir / $wmlfile "
fi
# Footer
echo '#include "pl/foot.wmi"' >> " $wmldir / $subdir / $wmlfile "
fi
2011-04-11 14:50:21 +00:00
# If the translation is German, include the
# correct header, menu files and footer
if [ $subdir = "de" ]
then
# Head
orig_head = ` grep '#include "head.wmi"' " $wmldir / $subdir / $wmlfile " `
new_head = ` echo $orig_head | sed s@head.wmi@de/head.wmi@`
sed -i " s@ $orig_head @ $new_head @ " " $wmldir / $subdir / $wmlfile "
# Side (not all files include this)
orig_side = ` grep '#include "side.wmi"' " $wmldir / $subdir / $wmlfile " `
if [ -n " $orig_side " ]
then
new_side = ` echo '#include "de/side.wmi"' `
sed -i " s@ $orig_side @ $new_side @ " " $wmldir / $subdir / $wmlfile "
fi
# Info (not all files include this)
orig_info = ` grep '#include "info.wmi"' " $wmldir / $subdir / $wmlfile " `
if [ -n " $orig_info " ]
then
new_info = ` echo '#include "de/info.wmi"' `
sed -i " s@ $orig_info @ $new_info @ " " $wmldir / $subdir / $wmlfile "
fi
# Footer
echo '#include "de/foot.wmi"' >> " $wmldir / $subdir / $wmlfile "
fi
2011-03-31 11:17:24 +00:00
# If the translation is Arabic, include the
# correct header, css, menu files and footer
if [ $subdir = "ar" ]
then
# Head
orig_head = ` grep '#include "head.wmi"' " $wmldir / $subdir / $wmlfile " `
temp_head = ` echo $orig_head | sed s@head.wmi@ar/head.wmi@`
new_head = ` echo $temp_head 'STYLESHEET="css/master-rtl.css"' `
sed -i " s@ $orig_head @ $new_head @ " " $wmldir / $subdir / $wmlfile "
# Side (not all files include this)
orig_side = ` grep '#include "side.wmi"' " $wmldir / $subdir / $wmlfile " `
if [ -n " $orig_side " ]
then
new_side = ` echo '#include "ar/side.wmi"' `
sed -i " s@ $orig_side @ $new_side @ " " $wmldir / $subdir / $wmlfile "
fi
# Info (not all files include this)
orig_info = ` grep '#include "info.wmi"' " $wmldir / $subdir / $wmlfile " `
if [ -n " $orig_info " ]
then
new_info = ` echo '#include "ar/info.wmi"' `
sed -i " s@ $orig_info @ $new_info @ " " $wmldir / $subdir / $wmlfile "
fi
# Footer
echo '#include "ar/foot.wmi"' >> " $wmldir / $subdir / $wmlfile "
fi
2011-03-30 14:08:39 +00:00
# If the directory does not include sidenav.wmi,
# copy it from the English directory (only if
# the English directory has this file)
if [ [ ! -e " $wmldir / $subdir /sidenav.wmi " && -e " $wmldir /en/sidenav.wmi " ] ]
then
cp " $wmldir /en/sidenav.wmi " " $wmldir / $subdir "
fi
2010-05-16 10:35:06 +00:00
fi
}
2009-12-13 19:49:01 +00:00
2010-08-18 19:27:29 +00:00
# Convert translations to directories such as website/torbrowser/nb/.
# Again, po4a will write the file and then delete it if less than 80% has been translated
2010-05-16 10:35:06 +00:00
function subdir {
# The location of the english wml file
english = " $wmldir / $subdir /en/ $wmlfile "
2010-03-15 18:42:19 +00:00
2010-05-16 10:35:06 +00:00
# Convert the files
2010-08-18 19:27:29 +00:00
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 "
2010-03-15 18:42:19 +00:00
2010-05-16 10:35:06 +00:00
# Check to see if the file was written
2010-08-18 19:27:29 +00:00
if [ -e " $wmldir / $subdir / $lang / $wmlfile " ]
2010-05-16 10:35:06 +00:00
then
# Remove last three lines in file
sed -i -e :a -e '$d;N;2,3ba' -e 'P;D' " $wmldir / $subdir / $lang / $wmlfile "
2011-03-22 15:51:53 +00:00
# Remove a specific comment from a specific file
if [ $wmlfile = = "download-easy.wml" ]
then
translator_comment = "# Translators: please point to the version of TBB in your language, if there is one."
sed -i " s/ $translator_comment // " " $wmldir / $subdir / $lang / $wmlfile "
fi
2011-03-22 12:39:46 +00:00
2011-03-30 14:08:39 +00:00
# Include the English footer for most of the
# translations
2011-04-12 18:14:51 +00:00
if [ [ $lang != "ar" && $lang != "pl" && $lang != "de" ] ]
2011-03-17 08:53:43 +00:00
then
2011-03-17 12:31:41 +00:00
echo '#include "foot.wmi"' >> " $wmldir / $subdir / $lang / $wmlfile "
2011-03-17 08:53:43 +00:00
fi
2011-03-30 14:08:39 +00:00
2011-06-29 19:05:15 +00:00
# If the file is overview.wml, make sure we
# include the correct set of images
if [ $wmlfile = "overview.wml" ] && [ [ $lang = "de" || $lang = "es" || $lang = "fr" ||
$lang = "ja" || $lang = "nl" || $lang = "no" || $lang = "pl" || $lang = "ru" ||
$lang = "zh" ] ]
then
sed -i " s/htw1.png/htw1_ $lang .png/ " " $wmldir / $subdir / $lang / $wmlfile "
sed -i " s/htw2.png/htw2_ $lang .png/ " " $wmldir / $subdir / $lang / $wmlfile "
sed -i " s/htw3.png/htw3_ $lang .png/ " " $wmldir / $subdir / $lang / $wmlfile "
fi
2011-03-31 11:17:24 +00:00
# If the translation is Polish, include the
# correct header, menu files and footer
if [ $lang = "pl" ]
then
orig_head = ` grep '#include "head.wmi"' " $wmldir / $subdir / $lang / $wmlfile " `
new_head = ` echo $orig_head | sed s@head.wmi@pl/head.wmi@`
sed -i " s@ $orig_head @ $new_head @ " " $wmldir / $subdir / $lang / $wmlfile "
# Side (not all files include this)
orig_side = ` grep '#include "side.wmi"' " $wmldir / $subdir / $lang / $wmlfile " `
if [ -n " $orig_side " ]
then
new_side = ` echo '#include "pl/side.wmi"' `
sed -i " s@ $orig_side @ $new_side @ " " $wmldir / $subdir / $lang / $wmlfile "
fi
# Info (not all files include this)
orig_info = ` grep '#include "info.wmi"' " $wmldir / $subdir / $lang / $wmlfile " `
if [ -n " $orig_info " ]
then
new_info = ` echo '#include "pl/info.wmi"' `
sed -i " s@ $orig_info @ $new_info @ " " $wmldir / $subdir / $lang / $wmlfile "
fi
# Footer
echo '#include "pl/foot.wmi"' >> " $wmldir / $subdir / $lang / $wmlfile "
fi
2011-04-11 14:50:21 +00:00
# If the translation is German, include the
# correct header, menu files and footer
if [ $lang = "de" ]
then
orig_head = ` grep '#include "head.wmi"' " $wmldir / $subdir / $lang / $wmlfile " `
new_head = ` echo $orig_head | sed s@head.wmi@de/head.wmi@`
sed -i " s@ $orig_head @ $new_head @ " " $wmldir / $subdir / $lang / $wmlfile "
# Side (not all files include this)
orig_side = ` grep '#include "side.wmi"' " $wmldir / $subdir / $lang / $wmlfile " `
if [ -n " $orig_side " ]
then
new_side = ` echo '#include "de/side.wmi"' `
sed -i " s@ $orig_side @ $new_side @ " " $wmldir / $subdir / $lang / $wmlfile "
fi
# Info (not all files include this)
orig_info = ` grep '#include "info.wmi"' " $wmldir / $subdir / $lang / $wmlfile " `
if [ -n " $orig_info " ]
then
new_info = ` echo '#include "de/info.wmi"' `
sed -i " s@ $orig_info @ $new_info @ " " $wmldir / $subdir / $lang / $wmlfile "
fi
# Footer
echo '#include "de/foot.wmi"' >> " $wmldir / $subdir / $lang / $wmlfile "
2011-07-06 18:48:32 +00:00
# If the file is tor-doc-windows, make
# sure we include the German video
if [ $wmlfile = "tor-doc-windows.wml" ]
then
2011-07-13 13:41:32 +00:00
orig_video = ` grep src = \" https:\/ \/ media.torproject.org\/ video\/ 2009-install-and-use-tor.ogv\" " $wmldir / $subdir / $lang / $wmlfile " `
new_video = ` echo " <p>Das nachfolgende Video, wurde von <a href=\"http://www.sempervideo.de/\">SemperVideo</a> erstellt.</p> $orig_video " `
sed -i " s@ $orig_video @ $new_video @ " " $wmldir / $subdir / $lang / $wmlfile "
sed -i "s@src\=\"https://media.torproject.org/video/2009-install-and-use-tor.ogv\"@src\=\"https://media.torproject.org/video/2011-install-and-use-tor-de.ogv\"@" " $wmldir / $subdir / $lang / $wmlfile "
2011-07-06 18:48:32 +00:00
fi
2011-04-11 14:50:21 +00:00
fi
2011-03-31 11:17:24 +00:00
# If the file is an Arabic translation, include the
# correct header, css, menu files and footer
if [ $lang = "ar" ]
then
# Head
orig_head = ` grep '#include "head.wmi"' " $wmldir / $subdir / $lang / $wmlfile " `
temp_head = ` echo $orig_head | sed s@head.wmi@ar/head.wmi@`
new_head = ` echo $temp_head 'STYLESHEET="css/master-rtl.css"' `
sed -i " s@ $orig_head @ $new_head @ " " $wmldir / $subdir / $lang / $wmlfile "
# Side (not all files include this)
orig_side = ` grep '#include "side.wmi"' " $wmldir / $subdir / $lang / $wmlfile " `
if [ -n " $orig_side " ]
then
new_side = ` echo '#include "ar/side.wmi"' `
sed -i " s@ $orig_side @ $new_side @ " " $wmldir / $subdir / $lang / $wmlfile "
fi
# Info (not all files include this)
orig_info = ` grep '#include "info.wmi"' " $wmldir / $subdir / $lang / $wmlfile " `
if [ -n " $orig_info " ]
then
new_info = ` echo '#include "ar/info.wmi"' `
sed -i " s@ $orig_info @ $new_info @ " " $wmldir / $subdir / $lang / $wmlfile "
fi
# Footer
echo '#include "ar/foot.wmi"' >> " $wmldir / $subdir / $lang / $wmlfile "
fi
2011-03-30 14:08:39 +00:00
# If the directory does not include sidenav.wmi,
# copy it from the English directory (only if
# the English directory has this file)
if [ [ ! -e " $wmldir / $subdir / $lang /sidenav.wmi " && -e " $wmldir / $subdir /en/sidenav.wmi " ] ]
then
cp " $wmldir / $subdir /en/sidenav.wmi " " $wmldir / $subdir / $lang / "
fi
2010-05-16 10:35:06 +00:00
fi
}
# If $onedirup is equal to $lang, that means we do not have a
# subdirectory.
if [ $onedirup = = $lang ]
then
# If the current subdirectory is "zh_CN" use "zh-cn" instead
if [ $subdir = "zh_CN" ]
then
subdir = "zh-cn"
nosubdir
2009-12-13 19:49:01 +00:00
fi
2009-12-22 11:08:55 +00:00
# If the current directory is "nb" use "no" instead
if [ $subdir = "nb" ]
then
2010-05-16 10:35:06 +00:00
subdir = "no"
nosubdir
2009-12-22 11:08:55 +00:00
fi
# If the current directory is "sv" use "se" instead
if [ $subdir = "sv" ]
then
2010-05-16 10:35:06 +00:00
subdir = "se"
nosubdir
2009-12-22 11:08:55 +00:00
fi
2011-03-22 13:48:25 +00:00
# If the current directory is "pl_PL" use "pl" instead
if [ $subdir = "pl_PL" ]
then
subdir = "pl"
nosubdir
fi
2009-12-13 19:49:01 +00:00
# Convert everything else
2011-03-31 11:17:24 +00:00
if [ [ $subdir != "en" && $subdir != "zh_CN" && $subdir != "nb" && $subdir != "sv" && $subdir != "pl_PL" ] ]
2009-08-16 08:11:41 +00:00
then
2010-05-16 10:35:06 +00:00
nosubdir
2009-08-16 08:11:41 +00:00
fi
else
2009-12-13 19:49:01 +00:00
# If the current language is "zh_CN" use "zh-cn" instead
if [ $lang = "zh_CN" ]
then
2010-05-16 10:35:06 +00:00
lang = "zh-cn"
subdir
2009-12-13 19:49:01 +00:00
fi
2009-12-22 11:08:55 +00:00
# If the current language is "nb" use "no" instead
if [ $lang = "nb" ]
then
2010-05-16 10:35:06 +00:00
lang = "no"
subdir
2009-12-22 11:08:55 +00:00
fi
# If the current language is "sv" use "se" instead
if [ $lang = "sv" ]
then
2010-05-16 10:35:06 +00:00
lang = "se"
subdir
2009-12-22 11:08:55 +00:00
fi
2011-03-22 13:48:25 +00:00
# If the current language is "pl_PL" use "pl" instead
if [ $lang = "pl_PL" ]
then
lang = "pl"
subdir
fi
2009-12-13 19:49:01 +00:00
# Convert everything else
2011-03-31 11:17:24 +00:00
if [ [ $lang != "en" && $lang != "zh_CN" && $lang != "nb" && $lang != "sv" && $lang != "pl_PL" ] ]
2009-08-16 08:11:41 +00:00
then
2010-05-16 10:35:06 +00:00
subdir
2009-08-16 08:11:41 +00:00
fi
fi
done