make_pot.sh 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/sh
  2. #
  3. # make_pot.sh - multi-language support script
  4. # Generate lang.pot
  5. #
  6. SRCDIR="../../Firmware"
  7. #
  8. #
  9. echo "make_pot.sh started" >&2
  10. #remove output file if exists
  11. if [ -e lang.pot ]; then rm lang.pot; fi
  12. lang_name="English"
  13. lang_short="en"
  14. po_date=$(date)
  15. #cat ../lang_en_cz.txt | sed "/^$/d;/^#/d" | sed '{N;s/\n/ /}' | sed -n '/\"\\x00\"$/p' | sed 's/ \"\\x00\"$//' > lang_pot_cz.tmp
  16. #cat ../lang_en_de.txt | sed "/^$/d;/^#/d" | sed '{N;s/\n/ /}' | sed -n '/\"\\x00\"$/p' | sed 's/ \"\\x00\"$//' > lang_pot_de.tmp
  17. #cat ../lang_en_es.txt | sed "/^$/d;/^#/d" | sed '{N;s/\n/ /}' | sed -n '/\"\\x00\"$/p' | sed 's/ \"\\x00\"$//' > lang_pot_es.tmp
  18. #cat ../lang_en_it.txt | sed "/^$/d;/^#/d" | sed '{N;s/\n/ /}' | sed -n '/\"\\x00\"$/p' | sed 's/ \"\\x00\"$//' > lang_pot_it.tmp
  19. #cat ../lang_en_pl.txt | sed "/^$/d;/^#/d" | sed '{N;s/\n/ /}' | sed -n '/\"\\x00\"$/p' | sed 's/ \"\\x00\"$//' > lang_pot_pl.tmp
  20. #cat lang_pot_cz.tmp lang_pot_de.tmp lang_pot_es.tmp lang_pot_it.tmp lang_pot_pl.tmp | sort -u > lang_pot.tmp
  21. #cat ../lang_en.txt | sed "/^$/d;/^#/d" > lang_pot.tmp
  22. #write po header
  23. echo "# Translation of Prusa-Firmware into $lang_name." > lang.pot
  24. echo "#" >> lang.pot
  25. echo 'msgid ""' >> lang.pot
  26. echo 'msgstr ""' >> lang.pot
  27. echo '"MIME-Version: 1.0\n"' >> lang.pot
  28. echo '"Content-Type: text/plain; charset=UTF-8\n"' >> lang.pot
  29. echo '"Content-Transfer-Encoding: 8bit\n"' >> lang.pot
  30. echo '"Language: '$lang_short'\n"' >> lang.pot
  31. echo '"Project-Id-Version: Prusa-Firmware\n"' >> lang.pot
  32. echo '"POT-Creation-Date: '$po_date'\n"' >> lang.pot
  33. echo '"PO-Revision-Date: '$po_date'\n"' >> lang.pot
  34. echo '"Language-Team: \n"' >> lang.pot
  35. echo '"X-Generator: Poedit 2.0.7\n"' >> lang.pot
  36. echo '"X-Poedit-SourceCharset: UTF-8\n"' >> lang.pot
  37. echo '"Last-Translator: \n"' >> lang.pot
  38. echo '"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"' >> lang.pot
  39. echo >> lang.pot
  40. #list .cpp, .c and .h files
  41. files=$(ls "$SRCDIR"/*.cpp "$SRCDIR"/*.c "$SRCDIR"/*.h)
  42. num_texts=$(grep '^#' -c ../lang_en.txt)
  43. #num_texts_nt=$(grep '^"' -c lang_en.txt)
  44. #echo " $num_texts texts, $num_texts_nt not translated" >&2
  45. echo " $num_texts texts" >&2
  46. #loop over all messages
  47. s0=''
  48. s1=''
  49. num=1
  50. cat ../lang_en.txt | sed "s/\\\\/\\\\\\\\/g" | while read -r s; do
  51. if [ -z "$s" ]; then
  52. echo " processing $num of $num_texts" >&2
  53. search=$(/bin/echo -e "$s0")
  54. found=$(grep -m1 -n -F "$search" $files | head -n1 | cut -f1-2 -d':' | sed "s/^.*\///")
  55. echo "$s1" | sed 's/ c=0//;s/ r=0//;s/^#/# /'
  56. echo "#: $found"
  57. #echo "#, fuzzy"
  58. /bin/echo -e "msgid $s0"
  59. echo 'msgstr ""'
  60. echo
  61. num=$((num+1))
  62. fi
  63. s1=$s0
  64. s0=$s
  65. done >> lang.pot
  66. #replace LF with CRLF
  67. sync
  68. sed -i 's/$/\r/' lang.pot
  69. echo "make_pot.sh finished" >&2
  70. read
  71. exit 0