forked from openscad/openscad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslation-update.sh
executable file
·141 lines (124 loc) · 4.12 KB
/
translation-update.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
#!/bin/sh
# see doc/translation.txt for more info
BASEDIR=$PWD
updatepot()
{
# check we have all files from POTFILES present
while read f
do
if [ ! -f "$f" ]; then
echo "cannot find file '$f' from POTFILES"
exit 1
fi
done < locale/POTFILES
grep ui_MainWindow.h locale/POTFILES >/dev/null 2>/dev/null
if [ $? -ne 0 ] ; then
echo "cannot find .../ui_xxxxx.h files. perhaps if you run make...?"
exit 1
fi
# extract example names from the index JSON file
cat -n examples/examples.json \
| grep '\[$' | sed -e 's/^[ \ŧ]*//; s/:.*//' \
| awk '{ printf "#: examples/examples.json:%d\nmsgid %s\nmsgstr \"\"\n\n", $1, $2 }' \
> ./locale/json-strings.pot
# extract strings from appdata file
itstool -o ./locale/appdata-strings.pot ./openscad.appdata.xml.in --its=./contrib/appdata.its
VER=`date +"%Y.%m.%d"`
OPTS=
OPTS=$OPTS' --package-name=OpenSCAD'
OPTS=$OPTS' --package-version='$VER
OPTS=$OPTS' --default-domain=openscad'
OPTS=$OPTS' --language=c++'
OPTS=$OPTS' --keyword=' #without WORD means not to use default keywords
OPTS=$OPTS' --keyword=_'
OPTS=$OPTS' --keyword=q_'
OPTS=$OPTS' --keyword=_:1,2c'
OPTS=$OPTS' --keyword=q_:1,2c'
OPTS=$OPTS' --keyword=ngettext:1,2'
OPTS=$OPTS' --files-from=./locale/POTFILES'
cmd="${GETTEXT_PATH}xgettext "$OPTS' -o ./locale/openscad-tmp.pot'
echo $cmd
$cmd
if [ ! $? = 0 ]; then
echo error running xgettext
exit 1
fi
# Try --no-fuzzy-matching ?
cmd="${GETTEXT_PATH}msgcat -o ./locale/openscad.pot ./locale/openscad-tmp.pot ./locale/json-strings.pot ./locale/appdata-strings.pot"
echo $cmd
$cmd
if [ ! $? = 0 ]; then
echo error running msgcat
exit 1
fi
sed -e s/"CHARSET"/"UTF-8"/g ./locale/openscad.pot > ./locale/openscad.pot.new && mv ./locale/openscad.pot.new ./locale/openscad.pot
rm -f ./locale/json-strings.pot ./locale/openscad-tmp.pot ./locale/appdata-strings.pot
}
updatepo()
{
for LANGCODE in `cat ./locale/LINGUAS | grep -v "#"`; do
OPTS='--update --backup=t'
cmd="$GETTEXT_PATH"'msgmerge '$OPTS' ./locale/'$LANGCODE'.po ./locale/openscad.pot'
echo $cmd
$cmd
if [ ! $? = 0 ]; then
echo error running msgmerge
exit 1
fi
done
}
updatemo()
{
SUFFIX="$1"
for LANGCODE in `cat locale/LINGUAS | grep -v "#"`; do
mkdir -p ./locale/$LANGCODE/LC_MESSAGES
OPTS='-c -v'
cmd="$GETTEXT_PATH"'msgfmt '$OPTS' -o ./locale/'$LANGCODE'/LC_MESSAGES/openscad.mo ./locale/'$LANGCODE'.po'
echo $cmd
$cmd
if [ ! $? = 0 ]; then
echo error running msgfmt
exit 1
fi
done
if which itstool > /dev/null 2>&1; then
# ugly workaround for bug https://bugs.freedesktop.org/show_bug.cgi?id=90937
for LANGCODE in `cat locale/LINGUAS | grep -v "#"`; do
ln -s openscad.mo ./locale/$LANGCODE/LC_MESSAGES/$LANGCODE.mo
done
# generate translated appdata file
itstool -j ./openscad.appdata.xml.in -o ./openscad.appdata.xml ./locale/*/LC_MESSAGES/[a-z][a-z].mo
# clean the mess
for LANGCODE in `cat locale/LINGUAS | grep -v "#"`; do
unlink ./locale/$LANGCODE/LC_MESSAGES/$LANGCODE.mo
done
else
if [ x"$(uname -s)" = x"Linux" ]; then
echo "itstool missing, won't apply translations to openscad.appdata.xml"
fi
cp -f ./openscad.appdata.xml.in ./openscad.appdata.xml
fi
if test -n "$SUFFIX"
then
echo "using suffix '$SUFFIX'"
fi
cp -f ./icons/openscad.desktop.in ./icons/openscad.desktop
sed -i.bak -e "s,@@openscad@@,openscad${SUFFIX}," ./icons/openscad.desktop
sed -i.bak -e "s,</id>,${SUFFIX}\\0,; s/openscad.desktop/openscad${SUFFIX}.desktop/; s/openscad.png/openscad${SUFFIX}.png/" ./openscad.appdata.xml
}
GETTEXT_PATH=""
#if [ "x$OPENSCAD_LIBRARIES" != x ]; then
# GETTEXT_PATH="$OPENSCAD_LIBRARIES/bin/"
#fi
SCRIPTDIR="`dirname \"$0\"`"
TOPDIR="`dirname \"$SCRIPTDIR\"`"
CURDIR="`python -c "import os; print(os.path.relpath(os.path.realpath('$BASEDIR'), '$TOPDIR'))"`"
cd "$TOPDIR" || exit 1
if [ "x$1" = xupdatemo ]; then
updatemo "$2"
else
echo "Generating POTFILES..."
BUILDDIR=$(find "$CURDIR" -name ui_MainWindow.h | grep OpenSCAD_autogen/include/ui_MainWindow.h | sed -e 's,/*OpenSCAD_autogen/include/ui_MainWindow.h,,')
./scripts/generate-potfiles.sh "$BUILDDIR" > locale/POTFILES
updatepot && updatepo && updatemo ""
fi