aboutsummaryrefslogtreecommitdiff
path: root/contrib/extract_translations/prepare-translation.sh
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2007-12-14 21:28:29 +0000
committerBadlop <badlop@process-one.net>2007-12-14 21:28:29 +0000
commit3174ea98f650f3a4b944434c90d4141792367346 (patch)
treeb2499ea300f06cf573c9f68c4c5eadecbc3e4071 /contrib/extract_translations/prepare-translation.sh
parent* src/ejabberd_s2s_out.erl: Bugfix (diff)
* src/msgs/*: Unified file format: First line is SVN Id
tag. Second is Language name. Next lines are authors, adding the new ones on top. Each string must be in a single line (to facilitate the automatic removal of unused strings). Last four lines report file format for Emacs and Vim. * contrib/extract_translations/prepare-translation.sh: New features: extract all translations, include explanation for translators in the file, remove unused strings from file, include unused strings in a section for reference, provide information about current translation and number of missing strings, compress the files to a zip * contrib/extract_translations/extract_translations.erl: Reverted to the original version SVN Revision: 1070
Diffstat (limited to '')
-rwxr-xr-xcontrib/extract_translations/prepare-translation.sh278
1 files changed, 184 insertions, 94 deletions
diff --git a/contrib/extract_translations/prepare-translation.sh b/contrib/extract_translations/prepare-translation.sh
index 64bd03993..f5b758f70 100755
--- a/contrib/extract_translations/prepare-translation.sh
+++ b/contrib/extract_translations/prepare-translation.sh
@@ -2,100 +2,190 @@
# Frontend for ejabberd's extract_translations.erl
# by Badlop
-# last updated: 8 December 2005
-
-while [ "$1" != "" ]
-do
- case "$1" in
- -help)
- echo "Options:"
- echo " -lang LANGUAGE"
- echo " -src FULL_PATH_EJABBERD"
- echo ""
- echo "Example:"
- echo " ./prepare-translation.sh -lang es -src /home/admin/ejabberd"
- exit 0
- ;;
- -lang)
- # This is the language to be extracted
- LANGU=$2
- shift
- shift
- ;;
- -src)
- # This is the path to the ejabberd source dir
- EJA_DIR=$2
- shift
- shift
- ;;
- *)
- echo "unknown option: '$1 $2'"
- shift
- shift
- ;;
- esac
-done
-
-# Where is Erlang binary
-ERL=`which erl`
-
-EXTRACT_DIR=$EJA_DIR/contrib/extract_translations/
-EXTRACT_ERL=extract_translations.erl
-EXTRACT_BEAM=extract_translations.beam
-SRC_DIR=$EJA_DIR/src
-MSGS_DIR=$SRC_DIR/msgs
-MSGS_FILE=$LANGU.msg
-MSGS_FILE2=$LANGU.msg.translate
-MSGS_PATH=$MSGS_DIR/$MSGS_FILE
-MSGS_PATH2=$MSGS_DIR/$MSGS_FILE2
-
-if !([[ -n $EJA_DIR ]])
-then
-echo "ejabberd dir does not exist: $EJA_DIR"
-fi
-
-if !([[ -x $EXTRACT_BEAM ]])
-then
-echo -n "Compiling extract_translations.erl: "
-sh -c "cd $EXTRACT_DIR; $ERL -compile $EXTRACT_ERL"
-fi
-echo ""
-echo -n "Extracting language strings for '$LANGU':"
-
-echo -n " new..."
-$ERL -pa $EXTRACT_DIR -noinput -noshell -s extract_translations -s init stop -extra $SRC_DIR $MSGS_PATH >$MSGS_PATH.new
-
-echo -n " old..."
-$ERL -pa $EXTRACT_DIR -noinput -noshell -s extract_translations -s init stop -extra -unused $SRC_DIR $MSGS_PATH >$MSGS_PATH.unused
-
-cat $MSGS_PATH >$MSGS_PATH2
-
-echo "" >>$MSGS_PATH2
-
-cat $MSGS_PATH.new >>$MSGS_PATH2
-rm $MSGS_PATH.new
-echo "" >>$MSGS_PATH2
+prepare_dirs ()
+{
+ # Where is Erlang binary
+ ERL=`which erl`
+
+ EJA_DIR=`pwd`/../..
+ EXTRACT_DIR=$EJA_DIR/contrib/extract_translations/
+ EXTRACT_ERL=extract_translations.erl
+ EXTRACT_BEAM=extract_translations.beam
+ SRC_DIR=$EJA_DIR/src
+ MSGS_DIR=$SRC_DIR/msgs
+
+ if !([[ -n $EJA_DIR ]])
+ then
+ echo "ejabberd dir does not exist: $EJA_DIR"
+ fi
+
+ if !([[ -x $EXTRACT_BEAM ]])
+ then
+ echo -n "Compiling extract_translations.erl: "
+ sh -c "cd $EXTRACT_DIR; $ERL -compile $EXTRACT_ERL"
+ echo "ok"
+ fi
+}
+
+extract_lang ()
+{
+ MSGS_FILE=$1
+ MSGS_FILE2=$MSGS_FILE.translate
+ MSGS_PATH=$MSGS_DIR/$MSGS_FILE
+ MSGS_PATH2=$MSGS_DIR/$MSGS_FILE2
+
+ echo -n "Extracting language strings for '$MSGS_FILE':"
+
+ echo -n " new..."
+ cd $SRC_DIR
+ $ERL -pa $EXTRACT_DIR -noinput -noshell -s extract_translations -s init stop -extra . $MSGS_PATH >$MSGS_PATH.new
+ sed -e 's/^% \.\//% /g;' $MSGS_PATH.new > $MSGS_PATH.new2
+ mv $MSGS_PATH.new2 $MSGS_PATH.new
+
+ echo -n " old..."
+ $ERL -pa $EXTRACT_DIR -noinput -noshell -s extract_translations -s init stop -extra -unused . $MSGS_PATH >$MSGS_PATH.unused
+ find_unused_full $MSGS_FILE $MSGS_FILE.unused
+
+ echo "" >$MSGS_PATH2
+ echo " ***** Translation file for ejabberd ***** " >>$MSGS_PATH2
+ echo "" >>$MSGS_PATH2
+
+ echo "" >>$MSGS_PATH2
+ echo " *** New strings: Can you please translate them? *** " >>$MSGS_PATH2
+ cat $MSGS_PATH.new >>$MSGS_PATH2
+
+ echo "" >>$MSGS_PATH2
+ echo "" >>$MSGS_PATH2
+ echo " *** Unused strings: They will be removed automatically *** " >>$MSGS_PATH2
+ cat $MSGS_PATH.unused.full >>$MSGS_PATH2
+
+ echo "" >>$MSGS_PATH2
+ echo "" >>$MSGS_PATH2
+ echo " *** Already translated strings: you can also modify any of them if you want *** " >>$MSGS_PATH2
+ echo "" >>$MSGS_PATH2
+ cat $MSGS_PATH.old_cleaned >>$MSGS_PATH2
+
+ echo "" >>$MSGS_PATH2
+
+ echo " ok"
+
+ rm $MSGS_PATH.new
+ rm $MSGS_PATH.old_cleaned
+ rm $MSGS_PATH.unused.full
+}
+
+extract_lang_all ()
+{
+ cd $MSGS_DIR
+
+ for i in *.msg; do
+ extract_lang $i;
+ done
+
+ echo -e "File\tMissing\tLanguage\t\tLast translator"
+ echo -e "----\t-------\t--------\t\t---------------"
+ for i in *.msg; do
+ MISSING=`cat $i.translate | grep "\", \"\"}." | wc -l`
+ LANGUAGE=`grep "Language:" $i.translate | sed 's/% Language: //g'`
+ LASTAUTH=`grep "Author:" $i.translate | head -n 1 | sed 's/% Author: //g'`
+ echo -e "$i\t$MISSING\t$LANGUAGE\t$LASTAUTH"
+ done
+
+ cd $MSGS_DIR
+ REVISION=`svn info | grep "^Rev" | head -1 | awk '{print $2}'`
+ zip $HOME/ejabberd-langs-$REVISION.zip *.translate;
+
+ rm *.translate
+}
+
+find_unused_full ()
+{
+ DATFILE=$1
+ DATFILEI=$1.old_cleaned
+ DELFILE=$2
+ cd msgs
+
+ DATFILE1=$DATFILE.t1
+ DATFILE2=$DATFILE.t2
+
+ DELFILE1=$DELFILE.t1
+ DELFILE2=$DELFILE.t2
+ DELFILEF=$DATFILE.unused.full
+ echo "" >$DELFILEF
+
+ grep -v "\\\\" $DELFILE >$DELFILE2
+ echo ENDFILEMARK >>$DELFILE2
+ cp $DATFILE $DATFILEI
+ cp $DATFILE $DATFILE2
+
+ until [[ $STRING == ENDFILEMARK ]]; do
+ cp $DELFILE2 $DELFILE1
+ cp $DATFILE2 $DATFILE1
+
+ STRING=`head -1 $DELFILE1`
+
+ cat $DATFILE1 | grep "$STRING" >>$DELFILEF
+ cat $DATFILE1 | grep -v "$STRING" >$DATFILE2
+ cat $DELFILE1 | grep -v "$STRING" >$DELFILE2
+ done
+
+ mv $DATFILE2 $DATFILEI
+
+ rm -f $MSGS_PATH.t1
+ rm $MSGS_PATH.unused
+ rm -f $MSGS_PATH.unused.t1
+ rm $MSGS_PATH.unused.t2
+
+ cd ..
+}
+
+translation_instructions ()
+{
+ echo ""
+ echo " A new file has been created for you, with the current, the new and the deprecated strings:"
+ echo " $MSGS_PATH2"
+ echo ""
+ echo " At the end of that file you will find the strings you must update:"
+ echo " - Untranslated strings are like this: {"March", ""}."
+ echo " To translate the string, add the text inside the commas. Example:"
+ echo " {"March", "Marzo"}."
+ echo " - Old strings that are not used: "Woowoa""
+ echo " Search the entire file for those strings and remove them"
+ echo ""
+ echo " Once you have translated all the strings and removed all the old ones,"
+ echo " rename the file to overwrite the previous one:"
+ echo " $MSGS_PATH"
+}
+
+case "$1" in
+ -help)
+ echo "Options:"
+ echo " -langall"
+ echo " -lang LANGUAGE_FILE"
+ echo ""
+ echo "Example:"
+ echo " ./prepare-translation.sh -lang es.msg"
+ exit 0
+ ;;
+ -lang)
+ LANGU=$2
+ prepare_dirs
+ extract_lang $LANGU
+ shift
+ shift
+ ;;
+ -langall)
+ prepare_dirs
+ extract_lang_all
+ shift
+ ;;
+ *)
+ echo "unknown option: '$1 $2'"
+ shift
+ shift
+ ;;
+esac
-cat $MSGS_PATH.unused >>$MSGS_PATH2
-rm $MSGS_PATH.unused
-
-echo " ok"
-
-echo ""
-echo "Process completed."
-
-echo ""
-echo " A new file has been created for you, with the current, the new and the deprecated strings:"
-echo " $MSGS_PATH2"
-echo ""
-echo " At the end of that file you will find the strings you must update:"
-echo " - Untranslated strings are like this: {"March", ""}."
-echo " To translate the string, add the text inside the commas. Example:"
-echo " {"March", "Marzo"}."
-echo " - Old strings that are not used: "Woowoa""
-echo " Search the entire file for those strings and remove them"
echo ""
-echo " Once you have translated all the strings and removed all the old ones,"
-echo " rename the file to overwrite the previous one:"
-echo " $MSGS_PATH"
+echo "End."