aboutsummaryrefslogtreecommitdiff
path: root/contrib/extract_translations/prepare-translation.sh
diff options
context:
space:
mode:
authorBadlop <badlop@process-one.net>2008-08-17 16:35:58 +0000
committerBadlop <badlop@process-one.net>2008-08-17 16:35:58 +0000
commit61a639d5d99416cdb5743413230fb9ddc36ecf91 (patch)
tree48c8678173ee05be1dbbb7bee0668b6e41d4aa90 /contrib/extract_translations/prepare-translation.sh
parent* src/msgs/sv.msg: Fixed formatting typos (diff)
* contrib/extract_translations/extract_translations.erl: Use
Gettext PO for translators, export to ejabberd MSG (EJAB-468) * contrib/extract_translations/prepare-translation.sh: Likewise * doc/guide.tex: Likewise * doc/guide.html: Likewise * src/Makefile.in: New option 'make translations' * src/msgs/ejabberd.pot: Template translation file * src/msgs/*.po: Generated from old MSG files * src/msgs/*.msg: Automatic exported from PO files SVN Revision: 1527
Diffstat (limited to '')
-rwxr-xr-xcontrib/extract_translations/prepare-translation.sh172
1 files changed, 151 insertions, 21 deletions
diff --git a/contrib/extract_translations/prepare-translation.sh b/contrib/extract_translations/prepare-translation.sh
index 2fd895bf5..d1c435fbe 100755
--- a/contrib/extract_translations/prepare-translation.sh
+++ b/contrib/extract_translations/prepare-translation.sh
@@ -8,10 +8,10 @@ prepare_dirs ()
# Where is Erlang binary
ERL=`which erl`
- EJA_DIR=`pwd`/../..
+ EJA_DIR=`pwd`/..
EXTRACT_DIR=$EJA_DIR/contrib/extract_translations/
- EXTRACT_ERL=extract_translations.erl
- EXTRACT_BEAM=extract_translations.beam
+ EXTRACT_ERL=$EXTRACT_DIR/extract_translations.erl
+ EXTRACT_BEAM=$EXTRACT_DIR/extract_translations.beam
SRC_DIR=$EJA_DIR/src
MSGS_DIR=$SRC_DIR/msgs
@@ -22,9 +22,7 @@ prepare_dirs ()
if !([[ -x $EXTRACT_BEAM ]])
then
- echo -n "Compiling extract_translations.erl: "
sh -c "cd $EXTRACT_DIR; $ERL -compile $EXTRACT_ERL"
- echo "ok"
fi
}
@@ -140,6 +138,116 @@ find_unused_full ()
cd ..
}
+extract_lang_srcmsg2po ()
+{
+ LANG_CODE=$1
+ MSGS_PATH=$MSGS_DIR/$LANG_CODE.msg
+ PO_PATH=$MSGS_DIR/$LANG_CODE.po
+
+ $ERL -pa $EXTRACT_DIR -pa $SRC_DIR -noinput -noshell -s extract_translations -s init stop -extra -srcmsg2po . $MSGS_PATH >$PO_PATH.1
+ sed -e 's/ \[\]$/ \"\"/g;' $PO_PATH.1 > $PO_PATH.2
+ msguniq --sort-by-file $PO_PATH.2 --output-file=$PO_PATH
+
+ rm $PO_PATH.*
+}
+
+extract_lang_src2pot ()
+{
+ LANG_CODE=ejabberd
+ MSGS_PATH=$MSGS_DIR/$LANG_CODE.msg
+ POT_PATH=$MSGS_DIR/$LANG_CODE.pot
+
+ echo -n "" >$MSGS_PATH
+ echo "% Language: Language Name" >>$MSGS_PATH
+ echo "% Author: Translator name and contact method" >>$MSGS_PATH
+ echo "" >>$MSGS_PATH
+
+ cd $SRC_DIR
+ $ERL -pa $EXTRACT_DIR -pa $SRC_DIR -noinput -noshell -s extract_translations -s init stop -extra -srcmsg2po . $MSGS_PATH >$POT_PATH.1
+ sed -e 's/ \[\]$/ \"\"/g;' $POT_PATH.1 > $POT_PATH.2
+ msguniq --sort-by-file $POT_PATH.2 --output-file=$POT_PATH
+
+ rm $POT_PATH.*
+ rm $MSGS_PATH
+}
+
+extract_lang_popot2po ()
+{
+ LANG_CODE=$1
+ PO_PATH=$MSGS_DIR/$LANG_CODE.po
+ POT_PATH=$MSGS_DIR/ejabberd.pot
+
+ msgmerge $PO_PATH $POT_PATH >$PO_PATH.translate 2>/dev/null
+ mv $PO_PATH.translate $PO_PATH
+}
+
+extract_lang_po2msg ()
+{
+ LANG_CODE=$1
+ PO_PATH=$LANG_CODE.po
+ MS_PATH=$PO_PATH.ms
+ MSGID_PATH=$PO_PATH.msgid
+ MSGSTR_PATH=$PO_PATH.msgstr
+ MSGS_PATH=$LANG_CODE.msg
+
+ cd $MSGS_DIR
+
+ # Check PO has correct ~
+ # Let's convert to C format so we can use msgfmt
+ PO_TEMP=$LANG_CODE.po.temp
+ cat $PO_PATH | sed 's/%/perc/g' | sed 's/~/%/g' | sed 's/#:.*/#, c-format/g' >$PO_TEMP
+ msgfmt $PO_TEMP --check-format
+ result=$?
+ rm $PO_TEMP
+ if [ $result -ne 0 ] ; then
+ exit 1
+ fi
+
+ msgattrib $PO_PATH --translated --no-fuzzy --no-obsolete --no-location --no-wrap | grep "^msg" | tail --lines=+3 >$MS_PATH
+ grep "^msgid" $PO_PATH.ms | sed 's/^msgid //g' >$MSGID_PATH
+ grep "^msgstr" $PO_PATH.ms | sed 's/^msgstr //g' >$MSGSTR_PATH
+ paste $MSGID_PATH $MSGSTR_PATH --delimiter=, | awk '{print "{" $0 "}."}' | sort -g >$MSGS_PATH
+
+ rm $MS_PATH
+ rm $MSGID_PATH
+ rm $MSGSTR_PATH
+}
+
+extract_lang_updateall ()
+{
+ echo "Generating POT"
+ extract_lang_src2pot
+
+ cd $MSGS_DIR
+ echo ""
+ echo -e "File Missing Language Last translator"
+ echo -e "---- ------- -------- ---------------"
+ for i in *.msg; do
+ LANG_CODE=${i%.msg}
+ echo -n $LANG_CODE | awk '{printf "%-6s", $1 }'
+
+ # Convert old MSG file to PO
+ PO=$LANG_CODE.po
+ [ -f $PO ] || extract_lang_srcmsg2po $LANG_CODE
+
+ extract_lang_popot2po $LANG_CODE
+ extract_lang_po2msg $LANG_CODE
+
+ MISSING=`msgfmt --statistics $PO 2>&1 | awk '{printf "%5s", $4 }'`
+ echo -n " $MISSING"
+
+ LANGUAGE=`grep "Language:" $PO | sed 's/\"X-Language: //g' | sed 's/\\\\n\"//g' | awk '{printf "%-12s", $1}'`
+ echo -n " $LANGUAGE"
+
+ LASTAUTH=`grep "Last-Translator" $PO | sed 's/\"Last-Translator: //g' | sed 's/\\\\n\"//g'`
+ echo " $LASTAUTH"
+ done
+ echo ""
+ rm messages.mo
+
+ cd ..
+}
+
translation_instructions ()
{
echo ""
@@ -158,34 +266,56 @@ translation_instructions ()
echo " $MSGS_PATH"
}
+prepare_dirs
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'"
+ -srcmsg2po)
+ LANG_CODE=$2
+ extract_lang_srcmsg2po $LANG_CODE
+ shift
+ shift
+ ;;
+ -popot2po)
+ LANG_CODE=$2
+ extract_lang_popot2po $LANG_CODE
shift
shift
;;
+ -src2pot)
+ extract_lang_src2pot
+ shift
+ ;;
+ -po2msg)
+ LANG_CODE=$2
+ extract_lang_po2msg $LANG_CODE
+ shift
+ shift
+ ;;
+ -updateall)
+ extract_lang_updateall
+ shift
+ ;;
+ *)
+ echo "Options:"
+ echo " -langall"
+ echo " -lang LANGUAGE_FILE"
+ echo " -srcmsg2po LANGUAGE Construct .msg file using source code to PO file"
+ echo " -src2pot Generate template POT file from source code"
+ echo " -popot2po LANGUAGE Update PO file with template POT file"
+ echo " -po2msg LANGUAGE Export PO file to MSG file"
+ echo " -updateall Generate POT and update all PO"
+ echo ""
+ echo "Example:"
+ echo " ./prepare-translation.sh -lang es.msg"
+ exit 0
+ ;;
esac
-
-echo ""
-echo "End."