From a07b7291b49d4314ff7d497894aa9c00db283a54 Mon Sep 17 00:00:00 2001 From: Yuri D'Elia <wavexx@thregr.org> Date: Wed, 30 Jun 2021 16:10:26 +0200 Subject: [PATCH] lang-add: handle duplicate translations and empty files --- lang/lang-add.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lang/lang-add.sh b/lang/lang-add.sh index 9439ae89..e4a67d66 100755 --- a/lang/lang-add.sh +++ b/lang/lang-add.sh @@ -31,9 +31,10 @@ 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 @@ -48,9 +49,10 @@ 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