|  | 
| 1 | 1 | #!/bin/sh | 
| 2 | 2 | 
 | 
| 3 | 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 | 
|  | 4 | +if [ ! -f ./options/locale/locale_en-US.json ]; then | 
| 14 | 5 |   echo "please run this script in the root directory of the project" | 
| 15 | 6 |   exit 1 | 
| 16 | 7 | fi | 
| 17 | 8 | 
 | 
| 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 | 
|  | 9 | +mv ./options/locale/locale_en-US.json ./options/ | 
| 40 | 10 | 
 | 
| 41 | 11 | # Remove translation under 25% of en_us | 
| 42 |  | -baselines=$(wc -l "./options/locale_en-US.ini" | cut -d" " -f1) | 
|  | 12 | +baselines=$(wc -l "./options/locale_en-US.json" | cut -d" " -f1) | 
| 43 | 13 | baselines=$((baselines / 4)) | 
| 44 |  | -for filename in ./options/locale/*.ini; do | 
|  | 14 | +for filename in ./options/locale/*.json; do | 
| 45 | 15 |   lines=$(wc -l "$filename" | cut -d" " -f1) | 
| 46 | 16 |   if [ $lines -lt $baselines ]; then | 
| 47 | 17 |     echo "Removing $filename: $lines/$baselines" | 
| 48 | 18 |     rm "$filename" | 
| 49 | 19 |   fi | 
| 50 | 20 | done | 
| 51 | 21 | 
 | 
| 52 |  | -mv ./options/locale_en-US.ini ./options/locale/ | 
|  | 22 | +mv ./options/locale_en-US.json ./options/locale/ | 
0 commit comments