make_po.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. if [ "$LANG" == "all" ]; then
  12. ./make_po.sh cz
  13. ./make_po.sh de
  14. ./make_po.sh es
  15. ./make_po.sh it
  16. ./make_po.sh pl
  17. exit 0
  18. fi
  19. echo "make_po.sh started" >&2
  20. echo " selected language=$LANG" >&2
  21. #remove output file if exists
  22. if [ -e lang_$LANG.po ]; then rm lang_$LANG.po; fi
  23. lang_name=$(\
  24. case "$LANG" in
  25. *en*) echo "English" ;;
  26. *cz*) echo "Czech" ;;
  27. *de*) echo "German" ;;
  28. *es*) echo "Spanish" ;;
  29. *it*) echo "Italian" ;;
  30. *pl*) echo "Polish" ;;
  31. esac)
  32. lang_short=$(\
  33. case "$LANG" in
  34. *en*) echo "en" ;;
  35. *cz*) echo "cs" ;;
  36. *de*) echo "de" ;;
  37. *it*) echo "it" ;;
  38. *es*) echo "es" ;;
  39. *pl*) echo "pl" ;;
  40. esac)
  41. po_date=$(date)
  42. #write po header
  43. echo "# Translation of Prusa-Firmware into $lang_name." > lang_$LANG.po
  44. echo "#" >> lang_$LANG.po
  45. echo 'msgid ""' >> lang_$LANG.po
  46. echo 'msgstr ""' >> lang_$LANG.po
  47. echo '"MIME-Version: 1.0\n"' >> lang_$LANG.po
  48. echo '"Content-Type: text/plain; charset=UTF-8\n"' >> lang_$LANG.po
  49. echo '"Content-Transfer-Encoding: 8bit\n"' >> lang_$LANG.po
  50. echo '"Language: '$lang_short'\n"' >> lang_$LANG.po
  51. echo '"Project-Id-Version: Prusa-Firmware\n"' >> lang_$LANG.po
  52. echo '"POT-Creation-Date: '$po_date'\n"' >> lang_$LANG.po
  53. echo '"PO-Revision-Date: '$po_date'\n"' >> lang_$LANG.po
  54. echo '"Language-Team: \n"' >> lang_$LANG.po
  55. echo '"X-Generator: Poedit 2.0.7\n"' >> lang_$LANG.po
  56. echo '"X-Poedit-SourceCharset: UTF-8\n"' >> lang_$LANG.po
  57. echo '"Last-Translator: \n"' >> lang_$LANG.po
  58. echo '"Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"' >> lang_$LANG.po
  59. echo >> lang_$LANG.po
  60. #list .cpp, .c and .h files
  61. files=$(ls "$SRCDIR"/*.cpp "$SRCDIR"/*.c "$SRCDIR"/*.h)
  62. num_texts=$(grep '^#' -c ../lang_en_$LANG.txt)
  63. num_texts_nt=$(grep '^\"\\x00\"' -c ../lang_en_$LANG.txt)
  64. echo " $num_texts texts, $num_texts_nt not translated" >&2
  65. #loop over all messages
  66. s0=''
  67. s1=''
  68. s2=''
  69. num=1
  70. cat ../lang_en_$LANG.txt | sed "s/\\\\/\\\\\\\\/g" | while read -r s; do
  71. if [ "$s" == "" ]; then
  72. echo " processing $num of $num_texts" >&2
  73. if [ "$s0" == "\"\\\\x00\"" ]; then
  74. search=$(/bin/echo -e "$s1")
  75. found=$(grep -m1 -n -F "$search" $files | head -n1 | cut -f1-2 -d':' | sed "s/^.*\///")
  76. echo "$s2" | sed 's/ c=0//;s/ r=0//;s/^#/# /'
  77. echo "#: $found"
  78. echo "#, fuzzy"
  79. /bin/echo -e "msgid $s1"
  80. echo 'msgstr ""'
  81. echo
  82. else
  83. search=$(/bin/echo -e "$s1")
  84. found=$(grep -m1 -n -F "$search" $files | head -n1 | cut -f1-2 -d':' | sed "s/^.*\///")
  85. echo "$s2" | sed 's/ c=0//;s/ r=0//;s/^#/# /'
  86. echo "#: $found"
  87. /bin/echo -e "msgid $s1"
  88. /bin/echo -e "msgstr $s0"
  89. echo
  90. fi
  91. num=$((num+1))
  92. fi
  93. s2=$s1
  94. s1=$s0
  95. s0=$s
  96. done >> lang_$LANG.po
  97. #replace LF with CRLF
  98. sync
  99. sed -i 's/$/\r/' lang_$LANG.po
  100. echo "make_po.sh finished" >&2
  101. #read
  102. exit 0