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