release.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/sh
  2. set -e
  3. set -x
  4. ROOT=$PWD
  5. OUTPUT=$ROOT/build
  6. LCONVERT_BIN=${LCONVERT_BIN:-lconvert}
  7. LRELEASE_BIN=${LRELEASE_BIN:-lrelease}
  8. LUPDATE_BIN=${LUPDATE_BIN:-lupdate}
  9. if [ ! -d $OUTPUT ]
  10. then
  11. mkdir $OUTPUT
  12. fi
  13. echo "Cleaning old .qm files..."
  14. rm -f $OUTPUT/*
  15. grep_count()
  16. {
  17. local PIECE=`echo "$1" | grep -o "$2"`
  18. if [ -n "$PIECE" ]; then
  19. RETVAL=`echo $PIECE | sed 's/[a-z ]//g'`
  20. echo $RETVAL
  21. return
  22. fi
  23. echo 0
  24. }
  25. echo "{" >> $OUTPUT/index_v2.json
  26. echo " \"file_type\" : \"MMC-TRANSLATION-INDEX\"," >> $OUTPUT/index_v2.json
  27. echo " \"version\" : 2," >> $OUTPUT/index_v2.json
  28. echo " \"languages\" : {" >> $OUTPUT/index_v2.json
  29. echo "Creating .qm files..."
  30. FIRST=true
  31. for ts_file in $(ls *.ts)
  32. do
  33. echo "Considering ${ts_file}"
  34. lang="${ts_file%.ts}"
  35. po_file="${lang}.po"
  36. $LCONVERT_BIN -locations absolute "$ts_file" -o "$po_file"
  37. if cat "${po_file}" | grep '\"X-Qt-Contexts: true\\n\"' > /dev/null ; then
  38. echo "Translation ${po_file} is OK"
  39. else
  40. echo "Translation ${po_file} is bad (missing X-Qt-Contexts)"
  41. exit 1
  42. fi
  43. if [ "$lang" = "pt" ]; then
  44. lang="pt_PT"
  45. fi
  46. echo " Create $lang.qm"
  47. $LRELEASE_BIN $ts_file -qm $OUTPUT/$lang.qm
  48. SHA1=`sha1sum $OUTPUT/$lang.qm | awk '{ print $1 }'`
  49. FILENAME="${SHA1}.class"
  50. cp "$OUTPUT/$lang.qm" "$OUTPUT/$FILENAME"
  51. # Create an index file with info about the amount of strings translated and expected hashes of the files (for local caching purposes)
  52. PO_STATS=`msgfmt --statistics --output=/dev/null ${po_file} 2>&1`
  53. UNTRANSLATED=$(grep_count "$PO_STATS" '[0-9]\+ untranslated messages\?')
  54. FUZZY=$(grep_count "$PO_STATS" '[0-9]\+ fuzzy translations\?')
  55. TRANSLATED=$(grep_count "$PO_STATS" '[0-9]\+ translated messages\?')
  56. FILESIZE=$(stat -c%s "$OUTPUT/$lang.qm")
  57. if [ "$FIRST" = true ]; then
  58. FIRST=false
  59. else
  60. # close previous scope
  61. echo " }," >> $OUTPUT/index_v2.json
  62. fi
  63. echo " \"$lang\" : {" >> $OUTPUT/index_v2.json
  64. echo " \"file\" : \"$FILENAME\"," >> $OUTPUT/index_v2.json
  65. echo " \"sha1\" : \"$SHA1\"," >> $OUTPUT/index_v2.json
  66. echo " \"size\" : $FILESIZE," >> $OUTPUT/index_v2.json
  67. echo " \"translated\" : $TRANSLATED," >> $OUTPUT/index_v2.json
  68. echo " \"fuzzy\" : $FUZZY," >> $OUTPUT/index_v2.json
  69. echo " \"untranslated\" : $UNTRANSLATED" >> $OUTPUT/index_v2.json
  70. # Create an index file with just the files (legacy)
  71. echo "$lang.qm" >> $OUTPUT/index
  72. rm "$po_file"
  73. done
  74. echo " }" >> $OUTPUT/index_v2.json
  75. echo " }" >> $OUTPUT/index_v2.json
  76. echo "}" >> $OUTPUT/index_v2.json
  77. echo "All done!"