extract-json 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #! /bin/bash
  2. # Extract strings from all JSON files in a directory into files with matching names ending with .pot.
  3. #
  4. # This script will extract strings from all JSON files in the directory
  5. # passed as first argument. The second argument is the destination
  6. # directory for the extracted message file.
  7. #
  8. # This script uses createjsoncontext to generate the actual message file
  9. # from the JSON file.
  10. #
  11. # This script is based on handle_json_files.sh from KDE's translation
  12. # scripts.
  13. # handle_json_files.sh is copyright 2014 Burkhard Lück <lueck@hube-lueck.de>
  14. scriptdir=$(dirname $0)
  15. extract() {
  16. basedir=$1
  17. dest=$2
  18. file=$3
  19. python3 $scriptdir/createjsoncontext.py $file $basedir json.$$.tmp
  20. if test $? -eq 1; then
  21. return
  22. fi
  23. echo "Extracted messages from $file"
  24. msguniq --to-code=UTF-8 -o json.$$ json.$$.tmp
  25. if test -f json.$$; then
  26. destfile="$dest/$(basename $file).pot"
  27. mv json.$$ $destfile
  28. fi
  29. rm -f json.$$ json.$$.tmp
  30. }
  31. dir=$1; shift
  32. dest=$1; shift
  33. for file in $(find -L "$dir" -name *.json | grep -v 'tests'); do
  34. extract $dir $dest $file
  35. done