Translation helper scripts
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.

poupdate 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #!/bin/bash
  2. #
  3. # Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt>
  4. # Copyright 2009, Andrius Štikonas <andrius@stikonas.eu>
  5. #
  6. # #
  7. # # This script is free software; you can redistribute it and/or modify
  8. # # it under the terms of the GNU General Public License 2 as published by
  9. # # the Free Software Foundation.
  10. #
  11. # # This script is distributed in the hope that it will be useful,
  12. # # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # # GNU General Public License for more details.
  15. # #
  16. # # You should have received a copy of the GNU General Public License
  17. # # along with this script; if not, write to the Free Software
  18. # # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. #
  20. # ths-poupdate.sh - takes a bunch of files from a single directory and transfers the translations therein to a translation file tree;
  21. # may use the new files either as primary, or as secondary translations.
  22. ## First - the necessary checks before going into the loop
  23. source "`dirname $0`/ths-variables"
  24. ## Declaring Functions
  25. function usage() {
  26. echo "Usage `basename $0` [options] <updated-file-dir> <translations-file-tree> <translations-template-tree>"
  27. echo
  28. echo "Options:"
  29. echo " -NS|--new-as-secondary - use newly translated file translations"
  30. echo " as secondary (default - use the new files"
  31. echo " as primary translations)"
  32. echo " -v|--verbose - print msgmerge output"
  33. echo " -s|--silent - print only summary"
  34. exit 1
  35. }
  36. ## OPTIONS
  37. while true
  38. do
  39. case $1 in
  40. -NS|--new-as-secondary)
  41. option_new_as_secondary="Y"
  42. shift
  43. ;;
  44. -v|--verbose)
  45. option_verbose="Y"
  46. shift
  47. ;;
  48. -s|--silent)
  49. option_silent="Y"
  50. shift
  51. ;;
  52. -*|--*)
  53. usage
  54. ;;
  55. *)
  56. break
  57. ;;
  58. esac
  59. done
  60. # Check and, if incorrect usage, print usage
  61. if [ $# -ne 3 ]; then
  62. usage
  63. fi
  64. ## Change paths to variables
  65. upd_dir=$1
  66. tra_tree=$2
  67. tpl_tree=$3
  68. newtrans=`cd $upd_dir; find . -name "*.po"`
  69. total_files=`echo $newtrans | wc -w`
  70. skipped_files=0
  71. processed_files=0
  72. changed_files=0
  73. if [ "$option_verbose" = "Y" ]; then
  74. echo "Checking if updated files are in the specified directory ..."
  75. elif [ ! "$option_silent" = "Y" ]; then
  76. echo -ne "\r$processed_files/$total_files processed"
  77. fi
  78. if [ "$newtrans" == "" ]; then
  79. echo -e $RED"\t\t... no updated files found in: $upd_dir"$ENDCOLOR
  80. exit 1
  81. else
  82. if [ "$option_verbose" = "Y" ]; then
  83. echo " ... they are."
  84. echo
  85. fi
  86. fi
  87. ## MAIN LOOP
  88. for updfile in $newtrans
  89. do
  90. if [ `cd "$tpl_tree"; find ${updfile}t 2> /dev/null | wc -l` -gt 1 ]; then
  91. if [ "$option_verbose" = "Y" ]; then
  92. echo
  93. echo "Strange, there is more than one template for `basename "$updfile"`,"
  94. echo "cannot determine the right one,"
  95. echo "SKIPPING..."
  96. fi
  97. continue
  98. fi
  99. if [ `cd "$tpl_tree"; find ${updfile} 2> /dev/null | wc -l` -gt 1 ]; then
  100. if [ "$option_verbose" = "Y" ]; then
  101. echo
  102. echo "Strange, there is more than one version of translation `basename $updfile`,"
  103. echo "although there is only one translation template. There might be an extra"
  104. echo "unneeded file in your translation tree, check it out!"
  105. echo "Cannot determine the right file to translate,"
  106. echo "SKIPPING..."
  107. fi
  108. continue
  109. fi
  110. if [ `cd $tpl_tree; find ${updfile}t 2> /dev/null | wc -l` -lt 1 ]; then
  111. if [ "$option_verbose" = "Y" ]; then
  112. echo
  113. echo -e "File $RED`basename "$updfile"`$ENDCOLOR does not belong to this translation project,"
  114. echo "SKIPPING..."
  115. find ${updfile}t -print
  116. fi
  117. skipped_files=$(($skipped_files+1))
  118. processed_files=$(($processed_files+1))
  119. continue
  120. fi
  121. if [ `cd "$tra_tree"; find ${updfile} 2> /dev/null | wc -l` -lt 1 ]; then
  122. echo
  123. echo -e "File $RED`basename $updfile`$ENDCOLOR is completely newly translated,"
  124. echo "COPYING it to the appropriate place..."
  125. #finding the appropriate
  126. tplfile=`cd "$tpl_tree"; find ${updfile}t`
  127. secdir=`dirname "$tplfile"`
  128. cp "$upd_dir/$updfile" "$tra_tree/$updfile"
  129. if [ svn ]; then
  130. svn add "$tra_tree/$updfile"
  131. fi
  132. fi
  133. # perform msgmerge and other actions
  134. trafile=`cd "$tra_tree"; find "$updfile"`
  135. tplfile=`cd "$tpl_tree"; find "${updfile}t"`
  136. mv "$tra_tree/$trafile" "$tra_tree/${trafile}.old"
  137. if [ ! "$option_new_as_secondary" = "Y" ]; then
  138. if [ "$option_verbose" = "Y" ]; then
  139. echo
  140. echo "UPDATING $trafile using translations from $upd_dir/$updfile as SECONDARY translations"
  141. msgmerge -N -v --compendium=$upd_dir/$updfile -o $tra_tree/${trafile}.new $tra_tree/${trafile}.old $tpl_tree/$tplfile
  142. else
  143. msgmerge -N -v --compendium=$upd_dir/$updfile -o $tra_tree/${trafile}.new $tra_tree/${trafile}.old $tpl_tree/$tplfile 2> /dev/null
  144. fi
  145. else
  146. if [ "$option_verbose" = "Y" ]; then
  147. echo
  148. echo "UPDATING $trafile using translations from $upd_dir/$updfile as PRIMARY translations"
  149. msgmerge -N -v --compendium=$tra_tree/${trafile}.old -o $tra_tree/${trafile}.new $upd_dir/$updfile $tpl_tree/$tplfile
  150. else
  151. msgmerge -N -v --compendium=$tra_tree/${trafile}.old -o $tra_tree/${trafile}.new $upd_dir/$updfile $tpl_tree/$tplfile 2> /dev/null
  152. fi
  153. fi
  154. # delete the Rosetta/Launchpad headers, only needed if the file was imported from Rosetta
  155. cat $tra_tree/${trafile}.new | sed '/X-Rosetta-Export-Date/d' > $tra_tree/$trafile
  156. if [ $diff ]; then
  157. if [ "`$diff $tra_tree/${trafile}.old $tra_tree/${trafile}.new`" ]; then
  158. changed_files=$(($changed_files+1))
  159. fi
  160. fi
  161. rm $tra_tree/${trafile}.old $tra_tree/${trafile}.new
  162. processed_files=$(($processed_files+1))
  163. if [ ! "$option_verbose" = "Y" ] && [ ! "$option_silent" = "Y" ]; then
  164. echo -ne "\r$processed_files/$total_files processed"
  165. if [ $diff ] && [ ! $changed_files -eq 0 ]; then
  166. echo -ne ", $changed_files changed"
  167. fi
  168. if [ ! $skipped_files -eq 0 ]; then
  169. echo -ne ", $skipped_files skipped"
  170. fi
  171. fi
  172. done
  173. echo -ne $BLUE"\r$processed_files/$total_files processed"$ENDCOLOR
  174. if [ $diff ] && [ ! $changed_files -eq 0 ]; then
  175. echo -ne $BLUE", $changed_files changed"$ENDCOLOR
  176. fi
  177. if [ ! $skipped_files -eq 0 ]; then
  178. echo -ne $BLUE", $skipped_files skipped"$ENDCOLOR
  179. fi
  180. echo