lang-add.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. #
  3. # lang-add.sh - multi-language support script
  4. # add new texts from list (lang_add.txt) to all dictionary files
  5. #
  6. # Input files:
  7. # lang_add.txt
  8. # Updated files:
  9. # lang_en.txt and all lang_en_xx.txt
  10. #
  11. # insert single text to english dictionary
  12. # $1 - text to insert
  13. insert_en()
  14. {
  15. # extract english texts, merge new text, grep line number
  16. ln=$((cat lang_en.txt; echo $1) | sed "/^$/d;/^#/d" | sort | grep -n "$1" | sed "s/:.*//")
  17. # calculate position for insertion
  18. ln=$((3*(ln-2)+1))
  19. # insert new text
  20. sed -i "$ln"'i\\' lang_en.txt
  21. sed -i "$ln"'i\'"$1"'\' lang_en.txt
  22. sed -i "$ln"'i\#\' lang_en.txt
  23. }
  24. # insert single text to translated dictionary
  25. # $1 - text to insert
  26. # $2 - sufix
  27. insert_xx()
  28. {
  29. ln=$((cat lang_en_$2.txt; echo $1) | sed "/^$/d;/^#/d" | sed -n 'p;n' | sort | grep -n "$1" | sed "s/:.*//")
  30. ln=$((4*(ln-2)+1))
  31. sed -i "$ln"'i\\' lang_en_$2.txt
  32. sed -i "$ln"'i\"\x00"\' lang_en_$2.txt
  33. sed -i "$ln"'i\'"$1"'\' lang_en_$2.txt
  34. sed -i "$ln"'i\#\' lang_en_$2.txt
  35. }
  36. # check if input file exists
  37. if ![ -e lang_add.txt ]; then
  38. echo "file lang_add.txt not found"
  39. exit 1
  40. fi
  41. cat lang_add.txt | sed 's/^/"/;s/$/"/' | while read new_s; do
  42. if grep "$new_s" lang_en.txt >/dev/nul; then
  43. echo "text already exist:"
  44. echo "$new_s"
  45. echo
  46. else
  47. echo "adding text:"
  48. echo "$new_s"
  49. echo
  50. insert_en "$new_s"
  51. insert_xx "$new_s" 'cz'
  52. insert_xx "$new_s" 'de'
  53. insert_xx "$new_s" 'es'
  54. insert_xx "$new_s" 'fr'
  55. insert_xx "$new_s" 'it'
  56. insert_xx "$new_s" 'pl'
  57. fi
  58. done
  59. read x
  60. exit 0