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
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

check-translation-status.sh 3.2 KiB

1 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/env bash
  2. print_usage() {
  3. echo "Check the translation status of a file"
  4. echo ""
  5. echo "Usage: ./check-translation-status.sh [-a] [-q] -f file.en.xml"
  6. echo ""
  7. echo " -f <FILENAME>"
  8. echo " (Relative or absolute path to file that shall be checked)"
  9. echo ""
  10. echo " -o up|out"
  11. echo " (Only print language code whose translations are up-to-date or outdated)"
  12. echo ""
  13. echo " -a (If given, checks all available translations of the file)"
  14. echo ""
  15. echo " -q (If given, do not write anything to STDOUT)"
  16. echo ""
  17. echo " -h (HELP)"
  18. echo ""
  19. echo "Exit codes:"
  20. echo " 0 = file is up-to-date"
  21. echo " 1 = file is outdated"
  22. echo " 2 = file is not supported"
  23. exit 0
  24. }
  25. basedir=$(dirname $(dirname $(realpath $0)))
  26. ALL="0"
  27. QUIET="0"
  28. while getopts f:o:aqh OPT; do
  29. case $OPT in
  30. f) FILE=$OPTARG;; # file name
  31. a) ALL="1";;
  32. q) QUIET="1";;
  33. o) ONLY=$OPTARG;; # print only languages which are up/outdated
  34. h) print_usage;;
  35. *) print_usage;;
  36. esac
  37. done
  38. # show usage if no required parameter given
  39. if [ "$1" = "" ] || [ -z "${FILE}" ]; then
  40. print_usage
  41. exit 0
  42. fi
  43. # -o suppresses all other output (-q), and implicates -a
  44. if [ -n "${ONLY}" ]; then
  45. QUIET="1"
  46. ALL="1"
  47. fi
  48. function out {
  49. if [ "${QUIET}" != "1" ]; then
  50. echo "$@"
  51. fi
  52. }
  53. # Get file extension
  54. EXT="${FILE##*.}"
  55. if ! [[ "${EXT}" =~ ^(xhtml|xml)$ ]]; then
  56. out "Only works for files ending with .xhtml or .xml"
  57. exit 2
  58. fi
  59. # remove "en.$EXT"
  60. BASE=$(echo "${FILE}" | sed -E "s/\.[a-z][a-z]\.${EXT}//")
  61. # get change date of English file
  62. EN="${BASE}".en."${EXT}"
  63. if [ ! -e "${EN}" ]; then
  64. out "English file does not exist. Aborting. (${EN})"
  65. exit 0
  66. fi
  67. envers=$(xsltproc ${basedir}/build/xslt/get_version.xsl "${EN}")
  68. out "Basefile: ${EN} (Version ${envers:-not set})"
  69. out " STATUS LANG VERSION"
  70. out " -------- ---- -------"
  71. if [ "${ALL}" == "1" ]; then
  72. # Loop over all translations of this file
  73. for i in "${BASE}".[a-z][a-z]."${EXT}"; do
  74. if [[ $i != *".en."* ]]; then
  75. # get language code
  76. lang=$(echo "${i}"|sed "s/.*\.\([a-z][a-z]\)\.${EXT}/\1/")
  77. # get version of translation
  78. trvers=$(xsltproc ${basedir}/build/xslt/get_version.xsl "${i}")
  79. # mark as outdated if version differs
  80. if [ ${trvers:-0} -lt ${envers:-0} ]; then
  81. out " OUTDATED ${lang} ${trvers:-not set}"
  82. # print outdated language code
  83. if [ "${ONLY}" == "out" ]; then
  84. echo "${lang}"
  85. fi
  86. else
  87. out " Up-to-date ${lang} ${trvers:-not set}"
  88. # print up-to-date language code
  89. if [ "${ONLY}" == "up" ]; then
  90. echo "${lang}"
  91. fi
  92. fi
  93. fi
  94. done | sort
  95. exit 0
  96. else
  97. i="${FILE}"
  98. if [[ $i != *".en."* ]]; then
  99. # get language code
  100. lang=$(echo "${i}"|sed "s/.*\.\([a-z][a-z]\)\.${EXT}/\1/")
  101. # get change date of translation
  102. trvers=$(xsltproc ${basedir}/build/xslt/get_version.xsl "${i}")
  103. # mark as outdated if version differs
  104. if [ ${trvers:-0} -lt ${envers:-0} ]; then
  105. out " OUTDATED ${lang} ${trvers:-not set}"
  106. exit 1
  107. else
  108. out " Up-to-date ${lang} ${trvers:-not set}"
  109. exit 0
  110. fi
  111. else
  112. out " (Comparing status of English file does not make sense)"
  113. fi
  114. fi