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.
|
|
|
|
#
|
|
|
|
#####################################
|
|
|
|
|
2018-05-25 13:26:36 +00:00
|
|
|
export LC_ALL=C
|
2016-08-01 21:59:48 +00:00
|
|
|
|
2016-08-02 15:54:20 +00:00
|
|
|
display_help() {
|
2020-10-20 21:38:08 +00:00
|
|
|
echo "Usage: $0 [-k] [-p] [-s=<path>] <locale|all>"
|
2016-08-02 15:54:20 +00:00
|
|
|
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
|
|
|
|
2020-10-20 21:38:08 +00:00
|
|
|
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
|
|
|
|
|
2016-08-01 21:59:48 +00:00
|
|
|
if [ -z ${SOURCEDIR} ]; then
|
2020-10-20 21:38:08 +00:00
|
|
|
SOURCEDIR=${DIR}/..
|
2016-08-01 21:59:48 +00:00
|
|
|
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
|
|
|
|
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
|
2023-01-01 23:12:41 +00:00
|
|
|
NPROC=`nproc --ignore=1`
|
2015-11-02 17:10:07 +00:00
|
|
|
|
|
|
|
#Generate/update template pot file
|
2021-01-16 19:23:30 +00:00
|
|
|
find $POTDIRS -name '*.cpp' -or -name '*.h' -or -name '*.xml.in' -or -name '*.desktop.in' |
|
2018-05-25 13:27:45 +00:00
|
|
|
sort |
|
2021-01-16 18:09:59 +00:00
|
|
|
xgettext -f- -k_ -k_HKI -kwxPLURAL:1,2 --force-po --from-code utf-8 -o $LOCALDIR/pofiles/kicad.pot
|
2015-11-02 17:10:07 +00:00
|
|
|
|
2021-01-16 18:08:19 +00:00
|
|
|
LINGUAS=`cat $LOCALDIR/pofiles/LINGUAS|grep -v '^#'|grep -v '^\s*$'` #Read file without comment and empty lines
|
2020-10-22 18:45:56 +00:00
|
|
|
|
2015-11-16 09:57:39 +00:00
|
|
|
#check if present in locale list
|
|
|
|
validate() { echo $LINGUAS | grep -F -q -w "$1"; }
|
|
|
|
|
2020-10-22 18:45:56 +00:00
|
|
|
if [ "$SINGLE_LANG" != "all" ] ; then
|
2015-11-16 09:57:39 +00:00
|
|
|
#If supplied, update only the specified locale
|
2020-10-22 18:45:56 +00:00
|
|
|
if [ "$SINGLE_LANG" = "" ] ; then
|
|
|
|
display_help
|
|
|
|
elif validate "$SINGLE_LANG"; then
|
|
|
|
LINGUAS="$SINGLE_LANG"
|
|
|
|
else
|
|
|
|
echo "Error!"
|
|
|
|
echo "Locale argument \"$1\" not present in current locale list:"
|
|
|
|
for i in $LINGUAS; do echo -n "$i "; done
|
|
|
|
echo # newline
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-11-16 09:57:39 +00:00
|
|
|
fi
|
|
|
|
|
2020-10-20 21:38:08 +00:00
|
|
|
|
2016-08-01 21:59:48 +00:00
|
|
|
echo "Writing summary to ${CSVFILE}"
|
|
|
|
echo "LANG;TRANSLATED;FUZZY;UNTRANSLATED" > "${CSVFILE}"
|
|
|
|
|
2023-01-01 23:12:41 +00:00
|
|
|
translate () {
|
|
|
|
if [ "$1" = "en" ] ; then
|
|
|
|
msgmerge --no-location --no-fuzzy-matching --force-po $LOCALDIR/pofiles/$1.po $LOCALDIR/pofiles/kicad.pot -o $LOCALDIR/pofiles/$1.po 2> /dev/null
|
|
|
|
msgen $LOCALDIR/pofiles/$1.po -o $LOCALDIR/pofiles/$1.po.tmp && mv $LOCALDIR/pofiles/$1.po.tmp $LOCALDIR/pofiles/$1.po
|
2019-01-31 12:04:13 +00:00
|
|
|
else
|
2023-01-01 23:12:41 +00:00
|
|
|
msgmerge --force-po $LOCALDIR/pofiles/$1.po $LOCALDIR/pofiles/kicad.pot -o $LOCALDIR/pofiles/$1.po 2> /dev/null
|
2017-06-18 20:16:41 +00:00
|
|
|
fi
|
2023-01-01 23:12:41 +00:00
|
|
|
|
|
|
|
msgfmt --statistics $LOCALDIR/pofiles/$1.po -o $LOCALDIR/pofiles/$1_messages.mo 2>&1 >>/dev/null |
|
2016-08-01 21:59:48 +00:00
|
|
|
while IFS=",." read A B C D ; do
|
2023-01-01 23:12:41 +00:00
|
|
|
echo -e "## $1\n$A\n$B\n$C\n$D"
|
2016-08-01 21:59:48 +00:00
|
|
|
|
|
|
|
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*}
|
|
|
|
;;
|
|
|
|
"" )
|
|
|
|
;;
|
|
|
|
* )
|
2023-01-01 23:12:41 +00:00
|
|
|
echo >&2 "$0: Unknown format of \"msgfmt --statistics $LOCALDIR/$1/kicad.po \": \"$STRING\""
|
2016-08-01 21:59:48 +00:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2023-01-01 23:12:41 +00:00
|
|
|
echo "$1;${TRANSLATED};${FUZZY};${UNTRANSLATED}">>"${CSVFILE}"
|
2016-08-01 21:59:48 +00:00
|
|
|
done
|
2023-01-01 23:12:41 +00:00
|
|
|
rm $LOCALDIR/pofiles/$1_messages.mo
|
|
|
|
}
|
|
|
|
|
|
|
|
for i in $LINGUAS
|
|
|
|
do
|
|
|
|
{
|
|
|
|
translate $i
|
|
|
|
} &
|
2015-11-02 17:10:07 +00:00
|
|
|
done
|
2023-01-01 23:12:41 +00:00
|
|
|
wait
|
2015-11-02 17:10:07 +00:00
|
|
|
|
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
|
2021-01-16 18:08:19 +00:00
|
|
|
rm $LOCALDIR/pofiles/kicad.pot
|
2015-11-20 10:58:03 +00:00
|
|
|
fi
|