make_po.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/sh
  2. #
  3. # make_po.sh - multi-language support script
  4. # for generating lang_xx.po
  5. #
  6. SRCDIR="../../Firmware"
  7. #
  8. LANG=$1
  9. if [ -z "$LANG" ]; then LANG=cz; fi
  10. #
  11. echo "make_po.sh started" >&2
  12. #remove output file if exists
  13. if [ -e lang_$LANG.po ]; then rm lang_$LANG.po; fi
  14. langname=$(\
  15. case "$LANG" in
  16. *en*) echo "English" ;;
  17. *cz*) echo "Czech" ;;
  18. *de*) echo "German" ;;
  19. *it*) echo "Italian" ;;
  20. *es*) echo "Spanish" ;;
  21. *pl*) echo "Polish" ;;
  22. esac)
  23. #write po header
  24. echo "# Translation into $langname." > lang_$LANG.po
  25. echo "#" >> lang_$LANG.po
  26. echo 'msgid ""' >> lang_$LANG.po
  27. echo 'msgstr ""' >> lang_$LANG.po
  28. echo '"MIME-Version: 1.0\n"' >> lang_$LANG.po
  29. echo '"Content-Type: text/plain; charset=UTF-8\n"' >> lang_$LANG.po
  30. echo '"Content-Transfer-Encoding: 8bit\n"' >> lang_$LANG.po
  31. echo >> lang_$LANG.po
  32. #list .cpp, .c and .h files
  33. files=$(ls "$SRCDIR"/*.cpp "$SRCDIR"/*.c "$SRCDIR"/*.h)
  34. #loop over all messages, print only untranslated (=="\x00")
  35. s0=''
  36. s1=''
  37. s2=''
  38. cat ../lang_en_$LANG.txt | sed "s/\\\\/\\\\\\\\/g;s/^#/#: /" | while read -r s; do
  39. if [ "$s" == "" ]; then
  40. if [ "$s0" == "\"\\\\x00\"" ]; then
  41. search=$(echo -e "$s1")
  42. found=$(grep -m1 -n -F "$search" $files | head -n1 | cut -f1-2 -d':' | sed "s/^.*\///")
  43. echo "#: $found"
  44. echo -e "msgid $s1"
  45. echo 'msgstr ""'
  46. echo
  47. fi
  48. fi
  49. s2=$s1
  50. s1=$s0
  51. s0=$s
  52. done >> lang_$LANG.po
  53. echo "make_po.sh finished" >&2
  54. exit 0