You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

update-locales.sh 1.6KB

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