Merge pull request #3215 from wavexx/lang_add_improvements
PFW-1297: lang-add.sh improvements
This commit is contained in:
commit
ab48e9880e
@ -7,7 +7,12 @@
|
||||
# lang_add.txt
|
||||
# Updated files:
|
||||
# lang_en.txt and all lang_en_xx.txt
|
||||
#
|
||||
|
||||
# List of supported languages
|
||||
LANGUAGES="cz de es fr it pl"
|
||||
|
||||
# Community languages
|
||||
LANGUAGES+=" nl" #Dutch
|
||||
|
||||
# Config:
|
||||
if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
|
||||
@ -21,36 +26,48 @@ echo "fw-clean languages:$LANGUAGES" >&2
|
||||
|
||||
# insert single text to english dictionary
|
||||
# $1 - text to insert
|
||||
# $2 - metadata
|
||||
insert_en()
|
||||
{
|
||||
#replace '[' and ']' in string with '\[' and '\]'
|
||||
str=$(echo "$1" | sed "s/\[/\\\[/g;s/\]/\\\]/g")
|
||||
# extract english texts, merge new text, grep line number
|
||||
ln=$((cat lang_en.txt; echo "$1") | sed "/^$/d;/^#/d" | sort | grep -n "$str" | sed "s/:.*//")
|
||||
ln=$((cat lang_en.txt; echo "$1") | sed "/^$/d;/^#/d" | sort | grep -n "$str" | sed "s/:.*//;q")
|
||||
# calculate position for insertion
|
||||
ln=$((3*(ln-2)+1))
|
||||
[ "$ln" -lt 1 ] && ln=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
|
||||
sed -i "${ln}i\\#$2" lang_en.txt
|
||||
}
|
||||
|
||||
# insert single text to translated dictionary
|
||||
# $1 - text to insert
|
||||
# $2 - sufix
|
||||
# $2 - suffix
|
||||
# $3 - metadata
|
||||
insert_xx()
|
||||
{
|
||||
#replace '[' and ']' in string with '\[' and '\]'
|
||||
str=$(echo "$1" | sed "s/\[/\\\[/g;s/\]/\\\]/g")
|
||||
# extract english texts, merge new text, grep line number
|
||||
ln=$((cat lang_en_$2.txt; echo "$1") | sed "/^$/d;/^#/d" | sed -n 'p;n' | sort | grep -n "$str" | sed "s/:.*//")
|
||||
ln=$((cat lang_en_$2.txt; echo "$1") | sed "/^$/d;/^#/d" | sed -n 'p;n' | sort | grep -n "$str" | sed "s/:.*//;q")
|
||||
# calculate position for insertion
|
||||
ln=$((4*(ln-2)+1))
|
||||
[ "$ln" -lt 1 ] && ln=1
|
||||
# insert new text
|
||||
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
|
||||
sed -i "${ln}i\\#$3" lang_en_$2.txt
|
||||
}
|
||||
|
||||
# find the metadata for the specified string
|
||||
# TODO: this is unbeliveably crude
|
||||
# $1 - text to search for
|
||||
find_metadata()
|
||||
{
|
||||
sed -ne "s^.*\(_[iI]\|ISTR\)($1).*////\(.*\)^\2^p" ../Firmware/*.[ch]* | head -1
|
||||
}
|
||||
|
||||
# check if input file exists
|
||||
@ -65,17 +82,15 @@ cat lang_add.txt | sed 's/^/"/;s/$/"/' | while read new_s; do
|
||||
echo "$new_s"
|
||||
echo
|
||||
else
|
||||
meta=$(find_metadata "$new_s")
|
||||
echo "adding text:"
|
||||
echo "$new_s"
|
||||
echo "$new_s ($meta)"
|
||||
echo
|
||||
#insert_en "$new_s"
|
||||
for lang in $LANGUAGES; do
|
||||
insert_xx "$new_s" "$lang"
|
||||
done
|
||||
|
||||
#Use the 2 lines below as a template and replace 'qr'
|
||||
##New language
|
||||
# insert_xx "$new_s" 'qr'
|
||||
insert_en "$new_s" "$meta"
|
||||
for lang in $LANGUAGES; do
|
||||
insert_xx "$new_s" "$lang" "$meta"
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user