Source files of fsfe.org, pdfreaders.org, freeyourandroid.org, ilovefs.org, drm.info, and test.fsfe.org. Contribute: https://fsfe.org/contribute/web/ https://fsfe.org
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.

encoding-convert.sh 1.1KB

1234567891011121314151617181920212223242526272829
  1. #!/bin/bash
  2. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
  3. # Select files
  4. #FILES=$(git grep -i -l "<\?xml.*encoding=\"iso" .)
  5. FILES=$(find . -type f)
  6. while read -r file; do
  7. enc=$(file --mime-encoding ${file} | cut -d" " -f2)
  8. # Only run if not correct encoding, and if XML, XHTML, or XSL file
  9. if [ "${enc}" != "utf-8" ] && [ "${enc}" != "us-ascii" ] && [ $(echo $file | grep -qoE "(\.xml$|\.xhtml$|\.xsl$)"; echo $?) -eq 0 ]; then
  10. # Only run if file is not outdated
  11. trstatus=$(tools/check-translation-status.sh -f "$file" -q; echo $?)
  12. if [ $trstatus = 0 ]; then
  13. # Convert to UTF-8
  14. iconv -f ${enc} -t UTF-8 ${file} -o ${file}.utf8
  15. # Replace XML encoding in first line
  16. sed -Ei "s@^<\?xml.*($enc|iso-8859-1|iso-8859-2|iso8859-1).*@<?xml version=\"1.0\" encoding=\"UTF-8\" ?>@I" ${file}.utf8
  17. # Move edited file to original location
  18. mv ${file}.utf8 ${file}
  19. # Status report
  20. enc_new=$(file --mime-encoding ${file} | cut -d" " -f2)
  21. echo "Converted $file from $enc to $enc_new"
  22. elif [ $trstatus = 1 ]; then
  23. echo "WARNING: $file is outdated"
  24. fi
  25. fi
  26. done <<< "${FILES}"