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.

autotranslate 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/bin/bash
  2. #
  3. # Copyright 2007, Donatas Glodenis <dgvirtual@akl.lt>
  4. #
  5. # #
  6. # # This script is free software; you can redistribute it and/or modify
  7. # # it under the terms of the GNU General Public License 2 as published by
  8. # # the Free Software Foundation.
  9. #
  10. # # This script is distributed in the hope that it will be useful,
  11. # # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # # GNU General Public License for more details.
  14. # #
  15. # # You should have received a copy of the GNU General Public License
  16. # # along with this script; if not, write to the Free Software
  17. # # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. #
  19. # ths-autotranslate.sh - automatically translates project files (may initialize files that have not been started to translate) using a specified compendium.
  20. source "`dirname $0`/ths-variables"
  21. function usage() {
  22. echo "Usage `basename $0` [options] <translation-files> <template-files>"
  23. echo
  24. echo "Options:"
  25. echo " -C|--use-compendium=some-compendium.po"
  26. echo " - use an external compendium during the migration"
  27. echo " -I|--initialize"
  28. echo " - initialize new translation files"
  29. echo " --no-wrap - do not wrap long lines"
  30. echo " --locale=lang - set locale for newly born files"
  31. exit 1
  32. }
  33. option_no_fuzzy_matching="--no-fuzzy-matching"
  34. option_verbose="Y"
  35. option_do_initialization="Y"
  36. while true
  37. do
  38. case $1 in
  39. -F|--use-fuzzy-matching)
  40. option_no_fuzzy_matching=""
  41. shift
  42. ;;
  43. -C=*|--use-compendium=*)
  44. option_use_own_compendium="$option_use_own_compendium --compendium=`echo $1 | sed 's/\-C=\|--use-compendium=//'`"
  45. shift
  46. ;;
  47. -I|--initialize)
  48. option_do_initialization="Y"
  49. shift
  50. ;;
  51. --no-wrap)
  52. option_no_wrap="--no-wrap"
  53. shift
  54. ;;
  55. --locale=*)
  56. option_locale=`echo $1 | sed 's/--locale=//'`
  57. shift
  58. ;;
  59. --locale)
  60. shift
  61. if [ $# -lt 1 ]; then
  62. usage
  63. fi
  64. option_locale=$1
  65. shift
  66. ;;
  67. -q|--quiet)
  68. option_verbose=""
  69. option_verbose_msgmerge="--quiet"
  70. shift
  71. ;;
  72. -*|--*)
  73. usage
  74. ;;
  75. *)
  76. break
  77. ;;
  78. esac
  79. done
  80. if [ $# -ne 2 ]; then
  81. usage
  82. fi
  83. new=$1
  84. templates=$2
  85. if [ "$option_do_initialization" = "Y" ]; then
  86. echo -n " ** New files will not be initialized ** "
  87. echo
  88. else
  89. echo "** Initializing new files... **"
  90. pots=`cd $templates; find . -name "*.pot"`
  91. if [ "$pots" == "" ]; then
  92. echo "No POT templates found in: $templates"
  93. exit 1
  94. fi
  95. for pot in $pots
  96. do
  97. # determine pot names according to the po names
  98. filename=`basename $pot .pot`.po
  99. directory=`dirname $pot`
  100. mkdir -p $new/$directory
  101. # copy a po file if an exact match is found for it in the templates directory
  102. if [ -f $new/$directory/$filename ]; then
  103. echo -n "file $new/$directory/$filename already exists, skipping creation..."
  104. echo
  105. else
  106. if [ ! $option_verbose ]; then
  107. msginit $option_no_wrap --locale=$option_locale --no-translator -i $templates/$pot -o $new/$directory/$filename 2>&1 | egrep -v "^Created"
  108. else
  109. msginit $option_no_wrap --locale=$option_locale --no-translator -i $templates/$pot -o $new/$directory/$filename
  110. fi
  111. fi
  112. done
  113. fi
  114. echo "** Updating files against templates (optionally with compendium)... **"
  115. for po in `cd $new ; find . -name "*.po" | sort`
  116. do
  117. [ $option_verbose ] && echo -n $new/$po
  118. msgmerge $option_verbose_msgmerge $option_no_fuzzy_matching $option_no_wrap $option_use_own_compendium --backup=off --update $new/$po $templates/${po}t
  119. done