92ec7d3d24
WIP
306 lines
9.3 KiB
Bash
Executable File
306 lines
9.3 KiB
Bash
Executable File
#!/bin/bash
|
||
#
|
||
# Version 1.0.1 Build 23
|
||
#
|
||
# lang-import.sh - multi-language support script
|
||
# for importing translated xx.po
|
||
#
|
||
#############################################################################
|
||
# Change log:
|
||
# 9 Nov 2018, XPila, Initial
|
||
# 14 Sep. 2019, 3d-gussner, Prepare adding new language
|
||
# 1 Mar. 2019, 3d-gussner, Move `Dutch` language parts
|
||
# Add templates for future community languages
|
||
# 17 Dec. 2021, 3d-gussner, Use one config file for all languages
|
||
# Fix missing last translation
|
||
# Add counter
|
||
# replace two double quotes with `\x00`
|
||
# 21 Dec. 2021, 3d-gussner, Add Swedish, Danish, Slovanian, Hungarian,
|
||
# Luxembourgish, Croatian
|
||
# 3 Jan. 2022, 3d-gussner, Add Lithuanian
|
||
# 11 Jan. 2022, 3d-gussner, Added version and Change log
|
||
# colored output
|
||
# Add Community language support
|
||
# Use `git rev-list --count HEAD lang-export.sh`
|
||
# to get Build Nr
|
||
#############################################################################
|
||
# Config:
|
||
if [ -z "$CONFIG_OK" ]; then eval "$(cat config.sh)"; fi
|
||
if [ -z "$CONFIG_OK" ] | [ $CONFIG_OK -eq 0 ]; then echo "$(tput setaf 1)Config NG!$(tput sgr 0)" >&2; exit 1; fi
|
||
|
||
echo "$(tput setaf 2)lang-import.sh started$(tput sgr 0)" >&2
|
||
|
||
if [ ! -z "$COMMUNITY_LANGUAGES" ]; then
|
||
LANGUAGES+=" $COMMUNITY_LANGUAGES"
|
||
fi
|
||
echo "$(tput setaf 2)lang-import languages:$LANGUAGES$(tput sgr 0)" >&2
|
||
|
||
LNG=$1
|
||
# if no arguments, 'all' is selected (all po and also pot will be generated)
|
||
if [ -z "$LNG" ]; then LNG=all; fi
|
||
|
||
# if 'all' is selected, script will generate all po files and also pot file
|
||
if [ "$LNG" = "all" ]; then
|
||
for lang in $LANGUAGES; do
|
||
./lang-import.sh $lang
|
||
done
|
||
exit 0
|
||
fi
|
||
|
||
# language code (iso639-1) is equal to LNG
|
||
LNGISO=$LNG
|
||
# exception for 'cz' (code='cs')
|
||
if [ "$LNG" = "cz" ]; then LNGISO=cs; fi
|
||
|
||
# cd to input folder
|
||
cd po/new
|
||
|
||
# check if input file exists
|
||
if ! [ -e $LNGISO.po ]; then
|
||
echo "$(tput setaf 1)Input file $LNGISO.po not found!$(tput sgr 0)" >&2
|
||
exit -1
|
||
fi
|
||
|
||
#convert '\\e' sequencies to 'x1b' and '\\' to '\'
|
||
cat $LNGISO.po | sed 's/\\e/\\x1b/g;s/\\\\/\\/g' > $LNG'_filtered.po'
|
||
|
||
#replace '\n' with ' ' (single space)
|
||
sed -i 's/ \\n/ /g;s/\\n/ /g' $LNG'_filtered.po'
|
||
|
||
#replace in czech translation
|
||
if [ "$LNG" = "cz" ]; then
|
||
#replace '<27>' with 'z'
|
||
sed -i 's/\xc5\xbe/z/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc4\x9b/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'i'
|
||
sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'r'
|
||
sed -i 's/\xc5\x99/r/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'c'
|
||
sed -i 's/\xc4\x8d/c/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a'
|
||
sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
#replace in german translation https://en.wikipedia.org/wiki/German_orthography
|
||
if [ "$LNG" = "de" ]; then
|
||
#replace '<27>' with 'ae'
|
||
sed -i 's/\xc3\xa4/ae/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'Ae'
|
||
sed -i 's/\xc3\x84/Ae/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'ue'
|
||
sed -i 's/\xc3\xbc/ue/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'Ue'
|
||
sed -i 's/\xc3\x9c/Ue/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'oe'
|
||
sed -i 's/\xc3\xb6/oe/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'Oe'
|
||
sed -i 's/\xc3\x96/Oe/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'ss'
|
||
sed -i 's/\xc3\x9f/ss/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
#replace in spain translation
|
||
if [ "$LNG" = "es" ]; then
|
||
#replace '<27>' with 'a'
|
||
sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with '?'
|
||
sed -i 's/\xc2\xbf/?/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'o'
|
||
sed -i 's/\xc3\xb3/o/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'i'
|
||
sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
|
||
#replace '!' with '!'
|
||
sed -i 's/\xc2\xa1/!/g' $LNG'_filtered.po'
|
||
#replace 'n~' with 'n'
|
||
sed -i 's/\xc3\xb1/n/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
#replace in french translation https://en.wikipedia.org/wiki/French_orthography
|
||
if [ "$LNG" = "fr" ]; then
|
||
#replace '<27>' with 'a' (right)
|
||
sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'A' (right)
|
||
sed -i 's/\xc3\x81/A/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a' (left)
|
||
sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'A' (left)
|
||
sed -i 's/\xc3\x80/A/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e' (right)
|
||
sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'E' (right)
|
||
sed -i 's/\xc3\x89/E/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e' (left)
|
||
sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'E' (left)
|
||
sed -i 's/\xc3\x88/E/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
#replace in italian translation
|
||
if [ "$LNG" = "it" ]; then
|
||
#replace '<27>' with 'e' (left)
|
||
sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a' (left)
|
||
sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'o' (left)
|
||
sed -i 's/\xc3\xb2/o/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'u' (left)
|
||
sed -i 's/\xc3\xb9/u/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'E' (left)
|
||
sed -i 's/\xc3\x88/E/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
#replace in dutch translation according to https://nl.wikipedia.org/wiki/Accenttekens_in_de_Nederlandse_spelling
|
||
if [ "$LNG" = "nl" ]; then
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'i'
|
||
sed -i 's/\xc3\xaf/i/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e' (left)
|
||
sed -i 's/\xc3\xa8/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'o' (left)
|
||
sed -i 's/\xc3\xb6/o/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e' (left)
|
||
sed -i 's/\xc3\xaa/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'u' (left)
|
||
sed -i 's/\xc3\xbc/u/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'c' (left)
|
||
sed -i 's/\xc3\xa7/c/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a' (left)
|
||
sed -i 's/\xc3\xa1/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a' (left)
|
||
sed -i 's/\xc3\xa0/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a' (left)
|
||
sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'u' (left)
|
||
sed -i 's/\xc3\xbc/u/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'i' (left)
|
||
sed -i 's/\xc3\xae/i/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'i' (left)
|
||
sed -i 's/\xc3\xad/i/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'o' (left)
|
||
sed -i 's/\xc3\xb4/o/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'u' (left)
|
||
sed -i 's/\xc3\xba/u/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'n' (left)
|
||
sed -i 's/\xc3\xb1/n/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a' (left)
|
||
sed -i 's/\xc3\xa2/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'A' (left)
|
||
sed -i 's/\xc3\x85/A/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
if [ "$LGN" = "sv" ]; then
|
||
#repace '<27>' with 'Aa'
|
||
sed -i 's/\xc3\x85/Aa/g' $LNG'_filtered.po'
|
||
#repace '<27>' with 'aa'
|
||
sed -i 's/\xc3\xA5/aa/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
if [ "$LGN" = "da" ]; then
|
||
#repace '<27>' with 'Aa'
|
||
sed -i 's/\xc3\x85/Aa/g' $LNG'_filtered.po'
|
||
#repace '<27>' with 'aa'
|
||
sed -i 's/\xc3\xA5/aa/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
if [ "$LGN" = "sl" ]; then
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a' (left)
|
||
sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
if [ "$LGN" = "hu" ]; then
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a'
|
||
sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
if [ "$LGN" = "lb" ]; then
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a'
|
||
sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
if [ "$LGN" = "hr" ]; then
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a'
|
||
sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
|
||
fi
|
||
|
||
if [ "$LGN" = "lt" ]; then
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xab/e/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'a'
|
||
sed -i 's/\xc3\xa4/a/g' $LNG'_filtered.po'
|
||
#replace '<27>' with 'e'
|
||
sed -i 's/\xc3\xa9/e/g' $LNG'_filtered.po'
|
||
fi
|
||
#replace in polish translation
|
||
#if [ "$LNG" = "pl" ]; then
|
||
#fi
|
||
|
||
#check for nonasci characters
|
||
if grep --color='auto' -P -n '[^\x00-\x7F]' $LNG'_filtered.po' >nonasci.txt; then
|
||
exit
|
||
fi
|
||
|
||
#join lines with multi-line string constants
|
||
cat $LNG'_filtered.po' | sed ':a;N;$!ba;s/\x22\n\x22//g' > $LNG'_new.po'
|
||
|
||
#Get counter from po files
|
||
|
||
CNTTXT=$(grep '^# MSG' -c $LNGISO.po)
|
||
num=1
|
||
echo " selected language=$(tput setaf 2)$LNGISO$(tput sgr 0)" >&2
|
||
#generate new dictionary
|
||
cat ../../lang_en.txt | sed 's/\\/\\\\/g' | while read -r s; do
|
||
/bin/echo -e "$s"
|
||
#echo "s = $s ." >&2
|
||
if [ "${s:0:1}" = "\"" ]; then
|
||
|
||
# /bin/echo -e "$s"
|
||
s=$(/bin/echo -e "$s")
|
||
s2=$(grep -F -A1 -B0 "msgid $s" "$LNG"_new.po | tail -n1 | sed 's/^msgstr //')
|
||
if [ -z "$s2" ]; then
|
||
echo -ne " processing $num of $CNTTXT\033[0K\r" >&2
|
||
echo '"\x00"'
|
||
num=$((num+1))
|
||
else
|
||
echo -ne " processing $num of $CNTTXT\033[0K\r" >&2
|
||
echo "$s2"
|
||
num=$((num+1))
|
||
fi
|
||
# echo
|
||
fi
|
||
|
||
done > lang_en_$LNG.txt
|
||
echo >&2
|
||
echo "$(tput setaf 2)Finished with $LNGISO$(tput sgr 0)" >&2
|
||
#replace two double quotes to "\x00"
|
||
sed -i 's/""/"\\x00"/g' lang_en_$LNG.txt
|
||
#remove CR
|
||
sed -i "s/\r//g" lang_en_$LNG.txt
|
||
echo >&2
|
||
echo "$(tput setaf 2)lang-import.sh finished$(tput sgr 0)">&2 |