1#!/bin/bash -e 2##################################### 3# 4# This program source code file is part of KiCad, a free EDA CAD application. 5# 6# Copyright (C) 2015 Marco Ciampa <ciampix@libero.it> 7# Copyright (C) 2015-2016 KiCad Developers 8# 9# License GNU GPL Version 3 or any later version. 10# 11##################################### 12 13export LC_ALL=C 14 15display_help() { 16 echo "Usage: $0 [-k] [-p] [-s=<path>] <locale|all>" 17 echo " -k keep pot template and not delete it" 18 echo " -p plot the translation statistics [requires python with matplotlib]" 19 echo " -s=<path> path to kicad source code" 20 exit 21} 22 23# Handle command line arguments 24for i in "$@"; do 25case $i in 26 -h|--help) 27 display_help 28 shift 29 ;; 30 -k) 31 KEEP=1 32 shift 33 ;; 34 -p) 35 PLOT=1 36 shift 37 ;; 38 -s=*) 39 SOURCEDIR="${i#*=}" 40 shift 41 ;; 42 *) 43 SINGLE_LANG=$i 44 ;; 45esac 46done 47 48DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 49 50if [ -z ${SOURCEDIR} ]; then 51 SOURCEDIR=${DIR}/.. 52 echo "Using default SOURCEDIR=${SOURCEDIR}" 53fi 54 55#Autovars 56cd $(dirname ${BASH_SOURCE[0]}) 57LOCALDIR=$PWD 58CSVFILE=${PWD}/i18n_status.csv 59POTDIRS=`cat $LOCALDIR/POTDIRS|grep -v '^#'|grep -v '^\s*$'` #Read file without comment and empty lines 60 61cd $SOURCEDIR 62 63#Generate/update template pot file 64find $POTDIRS -name '*.cpp' -or -name '*.h' -or -name '*.xml.in' -or -name '*.desktop.in' | 65 sort | 66 xgettext -f- -k_ -k_HKI -kwxPLURAL:1,2 --force-po --from-code utf-8 -o $LOCALDIR/pofiles/kicad.pot 67 68LINGUAS=`cat $LOCALDIR/pofiles/LINGUAS|grep -v '^#'|grep -v '^\s*$'` #Read file without comment and empty lines 69 70#check if present in locale list 71validate() { echo $LINGUAS | grep -F -q -w "$1"; } 72 73if [ "$SINGLE_LANG" != "all" ] ; then 74#If supplied, update only the specified locale 75 if [ "$SINGLE_LANG" = "" ] ; then 76 display_help 77 elif validate "$SINGLE_LANG"; then 78 LINGUAS="$SINGLE_LANG" 79 else 80 echo "Error!" 81 echo "Locale argument \"$1\" not present in current locale list:" 82 for i in $LINGUAS; do echo -n "$i "; done 83 echo # newline 84 exit 1 85 fi 86fi 87 88 89echo "Writing summary to ${CSVFILE}" 90echo "LANG;TRANSLATED;FUZZY;UNTRANSLATED" > "${CSVFILE}" 91 92for i in $LINGUAS 93do 94 echo "## $i" 95 if [ "$i" = "en" ] ; then 96 msgmerge --no-location --no-fuzzy-matching --force-po $LOCALDIR/pofiles/$i.po $LOCALDIR/pofiles/kicad.pot -o $LOCALDIR/pofiles/$i.po 2> /dev/null 97 msgen $LOCALDIR/pofiles/$i.po -o $LOCALDIR/pofiles/$i.po.tmp && mv $LOCALDIR/pofiles/$i.po.tmp $LOCALDIR/pofiles/$i.po 98 else 99 msgmerge --force-po $LOCALDIR/pofiles/$i.po $LOCALDIR/pofiles/kicad.pot -o $LOCALDIR/pofiles/$i.po 2> /dev/null 100 fi 101 msgfmt --statistics $LOCALDIR/pofiles/$i.po -o $LOCALDIR/pofiles/messages.mo 2>&1 >>/dev/null | 102 while IFS=",." read A B C D ; do 103 echo $A 104 echo $B 105 echo $C 106 echo $D 107 108 for STRING in "$A" "$B" "$C" "$D" ; do 109 STRING=${STRING# } 110 case "$STRING" in 111 *" translated message"* ) 112 TRANSLATED=${STRING% translated message*} 113 ;; 114 *" fuzzy translation"* ) 115 FUZZY=${STRING% fuzzy translation*} 116 ;; 117 *" untranslated message"* ) 118 UNTRANSLATED=${STRING% untranslated message*} 119 ;; 120 "" ) 121 ;; 122 * ) 123 echo >&2 "$0: Unknown format of \"msgfmt --statistics $LOCALDIR/$i/kicad.po \": \"$STRING\"" 124 exit 1 125 ;; 126 esac 127 done 128 echo "$i;${TRANSLATED};${FUZZY};${UNTRANSLATED}">>"${CSVFILE}" 129 done 130 rm $LOCALDIR/pofiles/messages.mo 131done 132 133if [ "$PLOT" = "1" ]; then 134 cd $LOCALDIR 135 $LOCALDIR/plot_i18n_status.py 136fi 137 138if [ ! "$KEEP" = "1" ]; then 139 rm $LOCALDIR/pofiles/kicad.pot 140fi 141