unique_pot.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. # When you copy templates from CKAN (or other plugins) you end up with already translated translations in your pot file.
  3. # This script filters them out from your .pot file. Run it right after `python setup.py extract_messages`
  4. PLUGIN_NAME=archiver
  5. PLUGIN_DEPENDENCIES=report
  6. SAVE_REUSED=0
  7. VERBOSE=0
  8. CURR_DIR=$(readlink -m $0/..)
  9. SRC_DIR=$(readlink -m $0/../../../../..)
  10. while getopts ":p:r:" opt; do
  11. case $opt in
  12. l) LANGUAGES="$OPTARG"
  13. ;;
  14. p) PLUGIN_DEPENDENCIES="$OPTARG"
  15. ;;
  16. r) SAVE_REUSED=1
  17. ;;
  18. v) VERBOSE=1
  19. ;;
  20. \?) echo "Invalid option -$OPTARG" >&2
  21. ;;
  22. esac
  23. done
  24. function run_verbose {
  25. if [ $VERBOSE ]; then
  26. echo "# Running: $1"
  27. fi
  28. eval $1
  29. }
  30. # Find strings that we have reused from core CKAN and other plugins
  31. DEP_POTS=""
  32. for PLUGIN in $PLUGIN_DEPENDENCIES; do
  33. DEP=$SRC_DIR/ckanext-$PLUGIN/ckanext/$PLUGIN/i18n/ckanext-$PLUGIN.pot
  34. if [ -f $DEP ]; then
  35. DEP_POTS="$DEP_POTS $DEP"
  36. else
  37. echo "Warning: .pot file for dependent $PLUGIN plugin doesn't exist, skipping $DEP"
  38. fi
  39. done
  40. run_verbose "msgcat $SRC_DIR/ckan/ckan/i18n/ckan.pot $DEP_POTS -o $CURR_DIR/_dependencies.pot"
  41. # Identify reused translations
  42. touch $CURR_DIR/_reused_translations.pot
  43. run_verbose "msgcat --use-first --more-than=1 $CURR_DIR/_dependencies.pot $CURR_DIR/ckanext-$PLUGIN_NAME.pot -o $CURR_DIR/_reused_translations.pot"
  44. # Leave only unique strings in our pot
  45. run_verbose "msgcat --unique $CURR_DIR/ckanext-$PLUGIN_NAME.pot $CURR_DIR/_reused_translations.pot -o $CURR_DIR/ckanext-$PLUGIN_NAME.pot"
  46. rm $CURR_DIR/_dependencies.pot
  47. if [ ! $SAVE_REUSED ]; then
  48. rm $CURR_DIR/_reused_translations.pot
  49. echo ""
  50. else
  51. echo "Saving $CURR_DIR/_reused_translations.pot"
  52. fi
  53. echo ""
  54. echo "I've updated $CURR_DIR/ckanext-$PLUGIN_NAME.pot."