GRASS manual translation: proposed script: Difference between revisions
Jump to navigation
Jump to search
m (used tag <source>) |
m (+cat) |
||
Line 1: | Line 1: | ||
Script to facilitate the creation of GRASS GIS manual pages in various languages: | |||
<source lang=bash> | <source lang=bash> | ||
#!/bin/bash | #!/bin/bash | ||
############################################################################ | ############################################################################ | ||
# | |||
# MODULE: grassdoclang.sh | |||
# AUTHOR(S): Marco Curreli | # AUTHOR(S): Marco Curreli | ||
# PURPOSE: build translation of GRASS full manual pages | # PURPOSE: build translation of GRASS full manual pages | ||
Line 12: | Line 14: | ||
# for details. | # for details. | ||
# | # | ||
# Tool to | # Tool to facilitate building GRASS GIS manual pages in your language, | ||
# including description and headers; the translation of the headers | # including description and headers; the translation of the headers | ||
# is made by extracting mstr from grassmods_lang.po file | # is made by extracting mstr from grassmods_lang.po file | ||
Line 380: | Line 382: | ||
exit 0 | exit 0 | ||
</source> | </source> | ||
[[Category: Documentation]] |
Revision as of 10:52, 17 February 2012
Script to facilitate the creation of GRASS GIS manual pages in various languages:
#!/bin/bash
############################################################################
#
# MODULE: grassdoclang.sh
# AUTHOR(S): Marco Curreli
# PURPOSE: build translation of GRASS full manual pages
# COPYRIGHT: (C) 2012 by Marco Curreli (at least for now)
#
# This program is free software under the GNU General Public
# License (>=v2). Read the file COPYING that comes with GRASS
# for details.
#
# Tool to facilitate building GRASS GIS manual pages in your language,
# including description and headers; the translation of the headers
# is made by extracting mstr from grassmods_lang.po file
#############################################################################
# Usage: grassdoclang.sh [options]
# inizializza le opzioni
# initiate flags
make_all="FALSE"
make_translation="FALSE"
make_man="FALSE"
display_help="FALSE"
proceed="FALSE"
# imposta le opzioni
# iet options
while getopts "atmh" opt
do
case "$opt" in
"a")
make_all="TRUE"
proceed="TRUE"
;;
"t")
make_translation="TRUE"
proceed="TRUE"
;;
"m")
make_man="TRUE"
proceed="TRUE"
;;
"h")
display_help="TRUE"
;;
"*")
echo "is not a valid option"
exit 1
;;
esac
done
shift $(($OPTIND - 1))
######## VARIABILI ########
######## VARIABLES ########
# imposta la lingua
# set lang
export lang=$(echo $LANG | cut -c 1-2)
# directory dei sorgenti di grass
# grass source directory
cd ../../..
export SRCGRASSDIR=$(pwd)
cd locale/desc/tools
# directory contenente i file description.html tradotti
# directory containing the translated files description.html
export DESCDIR=$SRCGRASSDIR/locale/desc
# directory dei manuali html
# html manuals directory
export HTMLDIR=$SRCGRASSDIR/dist.i686-pc-linux-gnu/docs/html
# elenco dei file description tradotti
# list of the description files translated
export FILE=$(ls $DESCDIR/$lang | grep html)
# directory dei manuali html completi tradotti
# directory of the html complete manuals translated
export HTMLlangDIR=$SRCGRASSDIR/dist.i686-pc-linux-gnu/docs/html_$lang
# directory e file .po
# .po directory and files
export PODIR=$SRCGRASSDIR/locale/po
export POFILE=grassmods_$lang.po
# dir. ed elenco dei messaggi(numero di riga della riga msgid del file .po)
# dir. and messages list (msgid row number of .po file)
export LSTMSGDIR=$SRCGRASSDIR/locale/desc/temp
export LSTMSG=$(cat $LSTMSGDIR/lstmsg_$lang)
# manuali html completi tradotti
# html complete manuals translated
export HTMLlangFILE=$(grep -l KEYWORD $HTMLlangDIR/*.html | grep -v r.li.html)
export html2man_dir=$SRCGRASSDIR/tools/g.html2man
export MANDIR=$SRCGRASSDIR/dist.i686-pc-linux-gnu/man
export MANlangDIR=$MANDIR/$lang
export FULLFILE=$(ls $HTMLlangDIR | grep html)
######## FUNZIONI ########
######## FUNCTIONS #######
displayHelp ()
{
cat <<'EOF'
Tool to facility building grass manual pages in your language,
including description and headers; the translation of the headers
is made by extracting mstr from grassmods_lang.po file
Usage: ./grassdoclang.sh [-a] | [-t] [-m] [-h]
Options:
-a executes the entire script
-t executes only header translation
-m only creates the man pages
-h display this help and exit
Note:
Option -a excludes other options
If both -t and -m are flagged, either -t and -m options are executed,
in this order
EOF
}
makeList ()
{
# crea il file con la lista dei msgid
# creates the msgid list file
echo "creazione dell'elenco dei messaggi po"
grep -n ^msgid $PODIR/$POFILE > $LSTMSGDIR/lstmsg_$lang
sed -i '
{
/\%./ d
/\.\.\./ d
/^#/ d
/\*/ d
/[Uu]nable to/ d
/[Cc]annot/ d
/[Cc]an not/ d
/Can.t/ d
/[Cc]ould not/ d
/[Ff]ailed to/ d
/[Ee]rror .*in/ d
/[Nn]o.*found/ d
/Please/ d
/[Pp]ermission denied/ d
s|:msgid.*||
1 d
} ' $LSTMSGDIR/lstmsg_$lang
}
docPrepare ()
{
# copia i file tradotti nelle ripettive directory
# e li rinomina in description.html
# copies translated files to respective directories
# and renames them description.html
mkdir $HTMLlangDIR
for file in $FILE
do
cd $SRCGRASSDIR
cd $(find -type d -name $(basename $file .html))
if [ -f ./description.html ] ; then
mv description.html description_en.html
cp -v ${DESCDIR}/$lang/$file description.html
else
mv $file ${file}_en
cp -v ${DESCDIR}/$lang/$file ./
fi
make clean && make
if [ -f $HTMLlangDIR/$file ] && $(diff $HTMLlangDIR/$file $HTMLDIR/$file >/dev/null) ; then
echo " file exists and is the same"
else
cp -v $HTMLDIR/$file $HTMLlangDIR
fi
done
for file in $FILE
do
cd $SRCGRASSDIR
cd $(find -type d -name $(basename $file .html))
mv -f -v description_en.html description.html
mv -v ${file}_en $file
make clean && make
done
}
headerTranslator ()
{
# traduce i messaggi dal file _lang.po
# translates messages of _lang.po files
for MSG in $LSTMSG
do
MSGID=$(
sed -n '
'"$MSG"',/^$/ {
/msgid/,/msgstr/ {
s|msgid \"||
/msgstr/ d
s|^\"||g
s|\"$||g
s|\\"|\"|g
s|%.*||g
s|\*.*||g
s|\.\.\.||
s|\\n|<br>|
p
}
} ' $PODIR/$POFILE
)
MSGSTR=$(
sed -n '
'"$MSG"',/^$/ {
/msgstr/,/^$/ {
s|msgstr "||
s|^\"||g
s|\"$||g
s|\\"|\"|g
s|\%.*||g
s|\*.*||g
s|\.\.\.||
s|\\n|<br>|
/^$/ d
p
}
} ' $PODIR/$POFILE
)
ID=$(echo $MSGID | sed -e 's|[]\[\^\$\.\*\/]|\\&|g' )
TR=$(echo $MSGSTR | sed -e 's|[]\[\^\$\.\*\/]|\\&|g' )
if echo $MSGSTR | grep -q [a-zA-Z]
then
sed -i '
/NAME/,/DESCRIPTION/ {
/NAME/,/KEYWORDS/ s@'"$ID"'$@'"$TR"'@
/NAME/,/KEYWORDS/ s@'"$ID"'<BR>$@'"$TR"'@
/KEYWORDS/,/SYNOPSIS/ s@'"$ID"'$@'"$TR"'@
/SYNOPSIS/,/DESCRIPTION/ s@<em>'"$ID"'<\/em>@<em>'"$TR"'<\/em>@g
/SYNOPSIS/,/DESCRIPTION/ s@<DD>'"$ID"'<\/DD>@<DD>'"$TR"'<\/DD>@g
} ' $HTMLlangFILE
fi
done
cp -n -v $HTMLDIR/*.png $HTMLlangDIR
cp -n -v $HTMLDIR/*.css $HTMLlangDIR
cp -n -v $HTMLDIR/*.txt $HTMLlangDIR
cp -n -v $HTMLDIR/*.jpg $HTMLlangDIR
exit 0
}
makeMan ()
{
# crea le pagine man
# creates the manpages
mkdir $MANDIR/$lang
mkdir $MANDIR/$lang/man1
for file in $FULLFILE
do
echo $file
perl $html2man_dir/g.html2man $HTMLlangDIR/$file $MANlangDIR/man1/$(basename $file .html).1 1
done
}
accent2html ()
{
# converte le lettere accentate in entità html
# converts accents to html entities
sed -i '
{
s|è|\è|g
s|é|\é|g
s|à|\à|g
s|ì|\ì|g
s|ò|\ò|g
s|ù|\ù|g
s|È|\È|g
s|À|\À|g
s|Ù|\Ù|g
} ' $HTMLlangDIR/*.html
}
html2accent ()
{
# converte entità html in lettere accentate
# converts html entities in accents
for m in $(ls $MANlangDIR/man1)
do
iconv -f ISO-8859-1 -t UTF-8 $m > $m.tmp
mv $m.tmp $m
done
sed -i '
{
s|\è|è|g
s|\é|é|g
s|\à|à|g
s|\ì|ì|g
s|\ò|ò|g
s|\ù|ù|g
s|\È|È|g
s|\À|À|g
s|\Ù|Ù|g
} ' $MANlangDIR/man1/*.1
}
########## AZIONI ###########
########## ACTIONS ##########
if [[ $display_help == TRUE ]] ; then
displayHelp
exit 0
fi
if [[ $make_all == TRUE && $make_translation == TRUE ]] ; then
echo " solo -a ..."
proceed="FALSE"
fi
if [[ $make_all == TRUE && $make_man == TRUE ]] ; then
echo " solo -a ..."
proceed="FALSE"
fi
# If the proceed flag isn't set, we don't proceed...
if [[ $proceed == "FALSE" ]]; then
echo "Please use repchars -h for usage instructions."
echo
exit 0;
fi
if [[$make_all == TRUE ]] ; then
echo " l'opzione -a esegue tutte le funzioni "
docPrepare && makeList && headerTranslator && accent2html && makeMan && html2accent
exit 0
fi
if [[ $make_translation == TRUE && $make_man == TRUE ]] ; then
echo "eseguite le opzioni -t e -m, in quest'ordine "
makeList && headerTranslator && accent2html && makeMan && html2accent
fi
if [[ $make_translation == TRUE ]] ; then
echo " -t traduce le intestazioni dei manuali "
makeList && headerTranslator
fi
if [[ $make_man == TRUE ]] ; then
echo " solo -m - create le pagine man "
accent2html && makeMan && html2accent
fi
exit 0