2018-05-30 18:15:05 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# make_po.sh - multi-language support script
|
|
|
|
# for generating lang_xx.po
|
|
|
|
#
|
|
|
|
SRCDIR="../../Firmware"
|
|
|
|
#
|
|
|
|
LANG=$1
|
|
|
|
if [ -z "$LANG" ]; then LANG=cz; fi
|
|
|
|
#
|
|
|
|
|
2018-05-31 11:53:24 +00:00
|
|
|
if [ "$LANG" == "all" ]; then
|
|
|
|
./make_po.sh cz
|
|
|
|
./make_po.sh de
|
|
|
|
./make_po.sh es
|
|
|
|
./make_po.sh it
|
|
|
|
./make_po.sh pl
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-05-30 18:15:05 +00:00
|
|
|
echo "make_po.sh started" >&2
|
2018-05-31 11:53:24 +00:00
|
|
|
echo " selected language=$LANG" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
|
|
|
|
#remove output file if exists
|
|
|
|
if [ -e lang_$LANG.po ]; then rm lang_$LANG.po; fi
|
|
|
|
|
2018-05-31 11:53:24 +00:00
|
|
|
lang_name=$(\
|
2018-05-30 18:15:05 +00:00
|
|
|
case "$LANG" in
|
|
|
|
*en*) echo "English" ;;
|
|
|
|
*cz*) echo "Czech" ;;
|
|
|
|
*de*) echo "German" ;;
|
|
|
|
*it*) echo "Italian" ;;
|
|
|
|
*es*) echo "Spanish" ;;
|
|
|
|
*pl*) echo "Polish" ;;
|
|
|
|
esac)
|
|
|
|
|
2018-05-31 11:53:24 +00:00
|
|
|
lang_short=$(\
|
|
|
|
case "$LANG" in
|
|
|
|
*en*) echo "en" ;;
|
|
|
|
*cz*) echo "cs" ;;
|
|
|
|
*de*) echo "de" ;;
|
|
|
|
*it*) echo "it" ;;
|
|
|
|
*es*) echo "es" ;;
|
|
|
|
*pl*) echo "pl" ;;
|
|
|
|
esac)
|
|
|
|
|
|
|
|
po_date=$(date)
|
|
|
|
|
2018-05-30 18:15:05 +00:00
|
|
|
#write po header
|
2018-05-31 11:53:24 +00:00
|
|
|
echo "# Translation of Prusa-Firmware into $lang_name." > lang_$LANG.po
|
2018-05-30 18:15:05 +00:00
|
|
|
echo "#" >> lang_$LANG.po
|
|
|
|
echo 'msgid ""' >> lang_$LANG.po
|
|
|
|
echo 'msgstr ""' >> lang_$LANG.po
|
|
|
|
echo '"MIME-Version: 1.0\n"' >> lang_$LANG.po
|
|
|
|
echo '"Content-Type: text/plain; charset=UTF-8\n"' >> lang_$LANG.po
|
|
|
|
echo '"Content-Transfer-Encoding: 8bit\n"' >> lang_$LANG.po
|
2018-05-31 11:53:24 +00:00
|
|
|
echo '"Language: '$lang_short'\n"' >> lang_$LANG.po
|
|
|
|
echo '"Project-Id-Version: Prusa-Firmware\n"' >> lang_$LANG.po
|
|
|
|
echo '"POT-Creation-Date: '$po_date'\n"' >> lang_$LANG.po
|
|
|
|
echo '"PO-Revision-Date: '$po_date'\n"' >> lang_$LANG.po
|
|
|
|
echo '"Language-Team: \n"' >> lang_$LANG.po
|
|
|
|
echo '"X-Generator: Poedit 2.0.7\n"' >> lang_$LANG.po
|
|
|
|
echo '"X-Poedit-SourceCharset: UTF-8\n"' >> lang_$LANG.po
|
|
|
|
echo '"Last-Translator: \n"' >> lang_$LANG.po
|
|
|
|
echo '"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"' >> lang_$LANG.po
|
2018-05-30 18:15:05 +00:00
|
|
|
echo >> lang_$LANG.po
|
|
|
|
|
|
|
|
#list .cpp, .c and .h files
|
|
|
|
files=$(ls "$SRCDIR"/*.cpp "$SRCDIR"/*.c "$SRCDIR"/*.h)
|
|
|
|
|
2018-05-31 11:53:24 +00:00
|
|
|
num_texts=$(grep '^#' -c ../lang_en_$LANG.txt)
|
|
|
|
num_texts_nt=$(grep '^\"\\x00\"' -c ../lang_en_$LANG.txt)
|
|
|
|
echo " $num_texts texts, $num_texts_nt not translated" >&2
|
|
|
|
|
|
|
|
#loop over all messages
|
2018-05-30 18:15:05 +00:00
|
|
|
s0=''
|
|
|
|
s1=''
|
|
|
|
s2=''
|
2018-05-31 11:53:24 +00:00
|
|
|
num=1
|
2018-05-30 18:15:05 +00:00
|
|
|
cat ../lang_en_$LANG.txt | sed "s/\\\\/\\\\\\\\/g;s/^#/#: /" | while read -r s; do
|
|
|
|
if [ "$s" == "" ]; then
|
2018-05-31 11:53:24 +00:00
|
|
|
echo " processing $num of $num_texts" >&2
|
2018-05-30 18:15:05 +00:00
|
|
|
if [ "$s0" == "\"\\\\x00\"" ]; then
|
|
|
|
search=$(echo -e "$s1")
|
|
|
|
found=$(grep -m1 -n -F "$search" $files | head -n1 | cut -f1-2 -d':' | sed "s/^.*\///")
|
|
|
|
echo "#: $found"
|
2018-05-31 11:53:24 +00:00
|
|
|
echo "#, fuzzy"
|
2018-05-30 18:15:05 +00:00
|
|
|
echo -e "msgid $s1"
|
|
|
|
echo 'msgstr ""'
|
|
|
|
echo
|
2018-05-31 11:53:24 +00:00
|
|
|
else
|
|
|
|
search=$(echo -e "$s1")
|
|
|
|
found=$(grep -m1 -n -F "$search" $files | head -n1 | cut -f1-2 -d':' | sed "s/^.*\///")
|
|
|
|
echo "#: $found"
|
|
|
|
echo -e "msgid $s1"
|
|
|
|
echo -e "msgstr $s0"
|
|
|
|
echo
|
2018-05-30 18:15:05 +00:00
|
|
|
fi
|
2018-05-31 11:53:24 +00:00
|
|
|
num=$((num+1))
|
2018-05-30 18:15:05 +00:00
|
|
|
fi
|
|
|
|
s2=$s1
|
|
|
|
s1=$s0
|
2018-05-31 11:53:24 +00:00
|
|
|
s0=$s
|
2018-05-30 18:15:05 +00:00
|
|
|
done >> lang_$LANG.po
|
|
|
|
|
2018-05-31 11:53:24 +00:00
|
|
|
#replace LF with CRLF
|
|
|
|
sync
|
|
|
|
sed -i 's/$/\r/' lang_$LANG.po
|
|
|
|
|
2018-05-30 18:15:05 +00:00
|
|
|
echo "make_po.sh finished" >&2
|
2018-05-31 11:53:24 +00:00
|
|
|
#read
|
2018-05-30 18:15:05 +00:00
|
|
|
exit 0
|