lang-add.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. fi
  53. done
  54. exit 0