2019-07-26 15:53:08 +00:00
|
|
|
#!/bin/bash
|
2018-11-01 16:29:26 +00:00
|
|
|
#
|
|
|
|
# lang-add.sh - multi-language support script
|
|
|
|
# add new texts from list (lang_add.txt) to all dictionary files
|
|
|
|
#
|
|
|
|
# Input files:
|
|
|
|
# lang_add.txt
|
|
|
|
# Updated files:
|
|
|
|
# lang_en.txt and all lang_en_xx.txt
|
2021-06-30 13:49:50 +00:00
|
|
|
|
|
|
|
# List of supported languages
|
|
|
|
LANGUAGES="cz de es fr it pl"
|
|
|
|
|
|
|
|
# Community languages
|
|
|
|
LANGUAGES+=" nl" #Dutch
|
2018-11-01 18:00:49 +00:00
|
|
|
|
2021-12-21 13:15:51 +00:00
|
|
|
# Config:
|
|
|
|
if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
|
|
|
|
if [ -z "$CONFIG_OK" ] | [ $CONFIG_OK -eq 0 ]; then echo 'Config NG!' >&2; exit 1; fi
|
|
|
|
|
|
|
|
if [ ! -z "$COMMUNITY_LANGUAGES" ]; then
|
|
|
|
LANGUAGES+=" $COMMUNITY_LANGUAGES"
|
|
|
|
fi
|
|
|
|
echo "fw-clean languages:$LANGUAGES" >&2
|
|
|
|
|
2018-11-01 16:29:26 +00:00
|
|
|
|
|
|
|
# insert single text to english dictionary
|
|
|
|
# $1 - text to insert
|
|
|
|
insert_en()
|
|
|
|
{
|
2018-11-06 15:23:01 +00:00
|
|
|
#replace '[' and ']' in string with '\[' and '\]'
|
|
|
|
str=$(echo "$1" | sed "s/\[/\\\[/g;s/\]/\\\]/g")
|
2018-11-01 16:29:26 +00:00
|
|
|
# extract english texts, merge new text, grep line number
|
2018-11-06 15:23:01 +00:00
|
|
|
ln=$((cat lang_en.txt; echo "$1") | sed "/^$/d;/^#/d" | sort | grep -n "$str" | sed "s/:.*//")
|
2018-11-01 16:29:26 +00:00
|
|
|
# calculate position for insertion
|
|
|
|
ln=$((3*(ln-2)+1))
|
|
|
|
# insert new text
|
|
|
|
sed -i "$ln"'i\\' lang_en.txt
|
|
|
|
sed -i "$ln"'i\'"$1"'\' lang_en.txt
|
|
|
|
sed -i "$ln"'i\#\' lang_en.txt
|
|
|
|
}
|
|
|
|
|
|
|
|
# insert single text to translated dictionary
|
|
|
|
# $1 - text to insert
|
|
|
|
# $2 - sufix
|
|
|
|
insert_xx()
|
|
|
|
{
|
2018-11-06 15:23:01 +00:00
|
|
|
#replace '[' and ']' in string with '\[' and '\]'
|
|
|
|
str=$(echo "$1" | sed "s/\[/\\\[/g;s/\]/\\\]/g")
|
|
|
|
# extract english texts, merge new text, grep line number
|
2019-02-07 13:36:03 +00:00
|
|
|
ln=$((cat lang_en_$2.txt; echo "$1") | sed "/^$/d;/^#/d" | sed -n 'p;n' | sort | grep -n "$str" | sed "s/:.*//")
|
2018-11-06 15:23:01 +00:00
|
|
|
# calculate position for insertion
|
2018-11-01 16:29:26 +00:00
|
|
|
ln=$((4*(ln-2)+1))
|
2018-11-06 15:23:01 +00:00
|
|
|
# insert new text
|
2018-11-01 16:29:26 +00:00
|
|
|
sed -i "$ln"'i\\' lang_en_$2.txt
|
|
|
|
sed -i "$ln"'i\"\x00"\' lang_en_$2.txt
|
|
|
|
sed -i "$ln"'i\'"$1"'\' lang_en_$2.txt
|
|
|
|
sed -i "$ln"'i\#\' lang_en_$2.txt
|
|
|
|
}
|
|
|
|
|
|
|
|
# check if input file exists
|
2018-11-06 15:23:01 +00:00
|
|
|
if ! [ -e lang_add.txt ]; then
|
2018-11-01 16:29:26 +00:00
|
|
|
echo "file lang_add.txt not found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
cat lang_add.txt | sed 's/^/"/;s/$/"/' | while read new_s; do
|
2019-10-23 10:44:11 +00:00
|
|
|
if grep "$new_s" lang_en.txt >/dev/null; then
|
2018-11-01 16:29:26 +00:00
|
|
|
echo "text already exist:"
|
|
|
|
echo "$new_s"
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
echo "adding text:"
|
|
|
|
echo "$new_s"
|
|
|
|
echo
|
2021-03-01 07:28:08 +00:00
|
|
|
|
2021-06-30 13:49:50 +00:00
|
|
|
insert_en "$new_s"
|
|
|
|
for lang in $LANGUAGES; do
|
|
|
|
insert_xx "$new_s" "$lang"
|
|
|
|
done
|
2018-11-01 16:29:26 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2020-05-12 20:23:40 +00:00
|
|
|
read -t 5
|
2021-12-21 13:15:51 +00:00
|
|
|
exit 0
|