code.gitea.io/gitea@v1.21.7/build/update-locales.sh (about) 1 #!/bin/sh 2 3 # this script runs in alpine image which only has `sh` shell 4 5 set +e 6 if sed --version 2>/dev/null | grep -q GNU; then 7 SED_INPLACE="sed -i" 8 else 9 SED_INPLACE="sed -i ''" 10 fi 11 set -e 12 13 if [ ! -f ./options/locale/locale_en-US.ini ]; then 14 echo "please run this script in the root directory of the project" 15 exit 1 16 fi 17 18 mv ./options/locale/locale_en-US.ini ./options/ 19 20 # the "ini" library for locale has many quirks, its behavior is different from Crowdin. 21 # see i18n_test.go for more details 22 23 # this script helps to unquote the Crowdin outputs for the quirky ini library 24 # * find all `key="...\"..."` lines 25 # * remove the leading quote 26 # * remove the trailing quote 27 # * unescape the quotes 28 # * eg: key="...\"..." => key=..."... 29 $SED_INPLACE -r -e '/^[-.A-Za-z0-9_]+[ ]*=[ ]*".*"$/ { 30 s/^([-.A-Za-z0-9_]+)[ ]*=[ ]*"/\1=/ 31 s/"$// 32 s/\\"/"/g 33 }' ./options/locale/*.ini 34 35 # * if the escaped line is incomplete like `key="...` or `key=..."`, quote it with backticks 36 # * eg: key="... => key=`"...` 37 # * eg: key=..." => key=`..."` 38 $SED_INPLACE -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*(".*[^"])$/\1=`\2`/' ./options/locale/*.ini 39 $SED_INPLACE -r -e 's/^([-.A-Za-z0-9_]+)[ ]*=[ ]*([^"].*")$/\1=`\2`/' ./options/locale/*.ini 40 41 # Remove translation under 25% of en_us 42 baselines=$(wc -l "./options/locale_en-US.ini" | cut -d" " -f1) 43 baselines=$((baselines / 4)) 44 for filename in ./options/locale/*.ini; do 45 lines=$(wc -l "$filename" | cut -d" " -f1) 46 if [ $lines -lt $baselines ]; then 47 echo "Removing $filename: $lines/$baselines" 48 rm "$filename" 49 fi 50 done 51 52 mv ./options/locale_en-US.ini ./options/locale/