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