2016-08-01 21:59:48 +00:00
|
|
|
#!/bin/bash -e
|
2015-11-02 17:10:07 +00:00
|
|
|
#####################################
|
|
|
|
#
|
|
|
|
# This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2015 Marco Ciampa <ciampix@libero.it>
|
2016-08-02 15:54:20 +00:00
|
|
|
# Copyright (C) 2015-2016 KiCad Developers
|
2015-11-02 17:10:07 +00:00
|
|
|
#
|
|
|
|
# License GNU GPL Version 3 or any later version.
|
|
|
|
#
|
|
|
|
#####################################
|
|
|
|
|
2016-08-01 21:59:48 +00:00
|
|
|
LANG=C
|
|
|
|
|
2016-08-02 15:54:20 +00:00
|
|
|
display_help() {
|
|
|
|
echo "Usage: $0 [-k] [-p] [locale]"
|
|
|
|
echo " -k keep pot template and not delete it"
|
|
|
|
echo " -p plot the translation statistics [requires python with matplotlib]"
|
2016-08-02 15:58:48 +00:00
|
|
|
echo " -s=<path> path to kicad source code"
|
2015-11-16 09:57:39 +00:00
|
|
|
exit
|
2016-08-02 15:54:20 +00:00
|
|
|
}
|
2015-11-16 09:57:39 +00:00
|
|
|
|
2016-08-02 15:54:20 +00:00
|
|
|
# Handle command line arguments
|
|
|
|
for i in "$@"; do
|
|
|
|
case $i in
|
|
|
|
-h|--help)
|
|
|
|
display_help
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
-k)
|
2015-11-20 10:58:03 +00:00
|
|
|
KEEP=1
|
|
|
|
shift
|
2016-08-02 15:54:20 +00:00
|
|
|
;;
|
|
|
|
-p)
|
|
|
|
PLOT=1
|
|
|
|
shift
|
|
|
|
;;
|
2016-08-02 15:58:48 +00:00
|
|
|
-s=*)
|
|
|
|
SOURCEDIR="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2016-08-02 15:54:20 +00:00
|
|
|
*)
|
|
|
|
SINGLE_LANG=$i
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2015-11-20 10:58:03 +00:00
|
|
|
|
2016-08-01 21:59:48 +00:00
|
|
|
if [ -z ${SOURCEDIR} ]; then
|
|
|
|
SOURCEDIR=../kicad-source-mirror
|
|
|
|
echo "Using default SOURCEDIR=${SOURCEDIR}"
|
|
|
|
fi
|
2015-11-02 17:10:07 +00:00
|
|
|
|
|
|
|
#Autovars
|
2016-08-02 15:54:20 +00:00
|
|
|
cd $(dirname ${BASH_SOURCE[0]})
|
2015-11-02 17:10:07 +00:00
|
|
|
LOCALDIR=$PWD
|
2016-08-02 15:54:20 +00:00
|
|
|
CSVFILE=${PWD}/i18n_status.csv
|
|
|
|
LINGUAS=`cat $LOCALDIR/LINGUAS|grep -v '^#'|grep -v '^\s*$'` #Read file without comment and empty lines
|
|
|
|
POTDIRS=`cat $LOCALDIR/POTDIRS|grep -v '^#'|grep -v '^\s*$'` #Read file without comment and empty lines
|
2015-11-02 17:10:07 +00:00
|
|
|
|
|
|
|
cd $SOURCEDIR
|
|
|
|
|
|
|
|
#Generate source file list
|
|
|
|
for f in $POTDIRS
|
|
|
|
do
|
|
|
|
find $f -name "*.cpp" >>$LOCALDIR/POTFILES #List files
|
|
|
|
find $f -name "*.h" >>$LOCALDIR/POTFILES #List files
|
|
|
|
done
|
|
|
|
|
|
|
|
#Generate/update template pot file
|
2017-12-21 18:23:55 +00:00
|
|
|
xgettext -f $LOCALDIR/POTFILES -k_ -k_HKI -kwxPLURAL:1,2 --force-po --from-code utf-8 -o $LOCALDIR/kicad.pot
|
2015-11-02 17:10:07 +00:00
|
|
|
|
|
|
|
rm $LOCALDIR/POTFILES
|
|
|
|
|
2015-11-16 09:57:39 +00:00
|
|
|
#check if present in locale list
|
|
|
|
validate() { echo $LINGUAS | grep -F -q -w "$1"; }
|
|
|
|
|
|
|
|
#If supplied, update only the specified locale
|
2016-08-02 15:54:20 +00:00
|
|
|
if [ ! "$SINGLE_LANG" = "" ] ; then
|
|
|
|
if ! validate "$SINGLE_LANG"; then
|
2015-11-16 09:57:39 +00:00
|
|
|
echo "Error!"
|
|
|
|
echo "Locale argument \"$1\" not present in current locale list:"
|
2016-08-02 15:54:20 +00:00
|
|
|
for i in $LINGUAS; do echo -n "$i "; done
|
|
|
|
echo # newline
|
2015-11-16 09:57:39 +00:00
|
|
|
exit 1
|
|
|
|
else
|
2016-08-02 15:54:20 +00:00
|
|
|
LINGUAS="$SINGLE_LANG"
|
2015-11-16 09:57:39 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2016-08-01 21:59:48 +00:00
|
|
|
echo "Writing summary to ${CSVFILE}"
|
|
|
|
echo "LANG;TRANSLATED;FUZZY;UNTRANSLATED" > "${CSVFILE}"
|
|
|
|
|
2015-11-02 17:10:07 +00:00
|
|
|
for i in $LINGUAS
|
|
|
|
do
|
2016-08-01 21:59:48 +00:00
|
|
|
echo "## $i"
|
|
|
|
msgmerge --force-po $LOCALDIR/$i/kicad.po $LOCALDIR/kicad.pot -o $LOCALDIR/$i/kicad.po 2> /dev/null
|
2017-06-18 20:16:41 +00:00
|
|
|
if [ "$i" = "en" ] ; then
|
|
|
|
msgen $LOCALDIR/$i/kicad.po -o $LOCALDIR/$i/kicad.po.tmp && mv $LOCALDIR/$i/kicad.po.tmp $LOCALDIR/$i/kicad.po
|
|
|
|
fi
|
2016-08-01 21:59:48 +00:00
|
|
|
msgfmt --statistics $LOCALDIR/$i/kicad.po 2>&1 >>/dev/null |
|
|
|
|
while IFS=",." read A B C D ; do
|
|
|
|
echo $A
|
|
|
|
echo $B
|
|
|
|
echo $C
|
|
|
|
echo $D
|
|
|
|
|
|
|
|
for STRING in "$A" "$B" "$C" "$D" ; do
|
|
|
|
STRING=${STRING# }
|
|
|
|
case "$STRING" in
|
|
|
|
*" translated message"* )
|
|
|
|
TRANSLATED=${STRING% translated message*}
|
|
|
|
;;
|
|
|
|
*" fuzzy translation"* )
|
|
|
|
FUZZY=${STRING% fuzzy translation*}
|
|
|
|
;;
|
|
|
|
*" untranslated message"* )
|
|
|
|
UNTRANSLATED=${STRING% untranslated message*}
|
|
|
|
;;
|
|
|
|
"" )
|
|
|
|
;;
|
|
|
|
* )
|
|
|
|
echo >&2 "$0: Unknown format of \"msgfmt --statistics $LOCALDIR/$i/kicad.po \": \"$STRING\""
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
echo "$i;${TRANSLATED};${FUZZY};${UNTRANSLATED}">>"${CSVFILE}"
|
|
|
|
done
|
2015-11-02 17:10:07 +00:00
|
|
|
done
|
|
|
|
|
2016-08-02 15:54:20 +00:00
|
|
|
if [ "$PLOT" = "1" ]; then
|
|
|
|
cd $LOCALDIR
|
|
|
|
$LOCALDIR/plot_i18n_status.py
|
|
|
|
fi
|
|
|
|
|
2015-11-20 10:58:03 +00:00
|
|
|
if [ ! "$KEEP" = "1" ]; then
|
|
|
|
rm $LOCALDIR/kicad.pot
|
|
|
|
fi
|