You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.6 KiB

  1. #!/bin/bash -e
  2. #####################################
  3. #
  4. # This program source code file is part of KiCad, a free EDA CAD application.
  5. #
  6. # Copyright (C) 2015 Marco Ciampa <ciampix@libero.it>
  7. # Copyright (C) 2015-2016 KiCad Developers
  8. #
  9. # License GNU GPL Version 3 or any later version.
  10. #
  11. #####################################
  12. export LC_ALL=C
  13. display_help() {
  14. echo "Usage: $0 [-k] [-p] [-s=<path>] <locale|all>"
  15. echo " -k keep pot template and not delete it"
  16. echo " -p plot the translation statistics [requires python with matplotlib]"
  17. echo " -s=<path> path to kicad source code"
  18. exit
  19. }
  20. # Handle command line arguments
  21. for i in "$@"; do
  22. case $i in
  23. -h|--help)
  24. display_help
  25. shift
  26. ;;
  27. -k)
  28. KEEP=1
  29. shift
  30. ;;
  31. -p)
  32. PLOT=1
  33. shift
  34. ;;
  35. -s=*)
  36. SOURCEDIR="${i#*=}"
  37. shift
  38. ;;
  39. *)
  40. SINGLE_LANG=$i
  41. ;;
  42. esac
  43. done
  44. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
  45. if [ -z ${SOURCEDIR} ]; then
  46. SOURCEDIR=${DIR}/..
  47. echo "Using default SOURCEDIR=${SOURCEDIR}"
  48. fi
  49. #Autovars
  50. cd $(dirname ${BASH_SOURCE[0]})
  51. LOCALDIR=$PWD
  52. CSVFILE=${PWD}/i18n_status.csv
  53. POTDIRS=`cat $LOCALDIR/POTDIRS|grep -v '^#'|grep -v '^\s*$'` #Read file without comment and empty lines
  54. cd $SOURCEDIR
  55. NPROC=`nproc --ignore=1`
  56. #Generate/update template pot file
  57. find $POTDIRS -name '*.cpp' -or -name '*.h' -or -name '*.xml.in' -or -name '*.desktop.in' |
  58. sort |
  59. xgettext -f- -k_ -k_HKI -kwxPLURAL:1,2 --force-po --from-code utf-8 -o $LOCALDIR/pofiles/kicad.pot
  60. LINGUAS=`cat $LOCALDIR/pofiles/LINGUAS|grep -v '^#'|grep -v '^\s*$'` #Read file without comment and empty lines
  61. #check if present in locale list
  62. validate() { echo $LINGUAS | grep -F -q -w "$1"; }
  63. if [ "$SINGLE_LANG" != "all" ] ; then
  64. #If supplied, update only the specified locale
  65. if [ "$SINGLE_LANG" = "" ] ; then
  66. display_help
  67. elif validate "$SINGLE_LANG"; then
  68. LINGUAS="$SINGLE_LANG"
  69. else
  70. echo "Error!"
  71. echo "Locale argument \"$1\" not present in current locale list:"
  72. for i in $LINGUAS; do echo -n "$i "; done
  73. echo # newline
  74. exit 1
  75. fi
  76. fi
  77. echo "Writing summary to ${CSVFILE}"
  78. echo "LANG;TRANSLATED;FUZZY;UNTRANSLATED" > "${CSVFILE}"
  79. translate () {
  80. if [ "$1" = "en" ] ; then
  81. msgmerge --no-location --no-fuzzy-matching --force-po $LOCALDIR/pofiles/$1.po $LOCALDIR/pofiles/kicad.pot -o $LOCALDIR/pofiles/$1.po 2> /dev/null
  82. msgen $LOCALDIR/pofiles/$1.po -o $LOCALDIR/pofiles/$1.po.tmp && mv $LOCALDIR/pofiles/$1.po.tmp $LOCALDIR/pofiles/$1.po
  83. else
  84. msgmerge --force-po $LOCALDIR/pofiles/$1.po $LOCALDIR/pofiles/kicad.pot -o $LOCALDIR/pofiles/$1.po 2> /dev/null
  85. fi
  86. msgfmt --statistics $LOCALDIR/pofiles/$1.po -o $LOCALDIR/pofiles/$1_messages.mo 2>&1 >>/dev/null |
  87. while IFS=",." read A B C D ; do
  88. echo -e "## $1\n$A\n$B\n$C\n$D"
  89. for STRING in "$A" "$B" "$C" "$D" ; do
  90. STRING=${STRING# }
  91. case "$STRING" in
  92. *" translated message"* )
  93. TRANSLATED=${STRING% translated message*}
  94. ;;
  95. *" fuzzy translation"* )
  96. FUZZY=${STRING% fuzzy translation*}
  97. ;;
  98. *" untranslated message"* )
  99. UNTRANSLATED=${STRING% untranslated message*}
  100. ;;
  101. "" )
  102. ;;
  103. * )
  104. echo >&2 "$0: Unknown format of \"msgfmt --statistics $LOCALDIR/$1/kicad.po \": \"$STRING\""
  105. exit 1
  106. ;;
  107. esac
  108. done
  109. echo "$1;${TRANSLATED};${FUZZY};${UNTRANSLATED}">>"${CSVFILE}"
  110. done
  111. rm $LOCALDIR/pofiles/$1_messages.mo
  112. }
  113. for i in $LINGUAS
  114. do
  115. {
  116. translate $i
  117. } &
  118. done
  119. wait
  120. if [ "$PLOT" = "1" ]; then
  121. cd $LOCALDIR
  122. $LOCALDIR/plot_i18n_status.py
  123. fi
  124. if [ ! "$KEEP" = "1" ]; then
  125. rm $LOCALDIR/pofiles/kicad.pot
  126. fi