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
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

check-translation-status.sh 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. ALL="0"
  26. QUIET="0"
  27. while getopts f:o:aqh OPT; do
  28. case $OPT in
  29. f) FILE=$OPTARG;; # file name
  30. a) ALL="1";;
  31. q) QUIET="1";;
  32. o) ONLY=$OPTARG;; # print only languages which are up/outdated
  33. h) print_usage;;
  34. *) print_usage;;
  35. esac
  36. done
  37. # show usage if no required parameter given
  38. if [ "$1" = "" ] || [ -z "${FILE}" ]; then
  39. print_usage
  40. exit 0
  41. fi
  42. # -o suppresses all other output (-q), and implicates -a
  43. if [ -n "${ONLY}" ]; then
  44. QUIET="1"
  45. ALL="1"
  46. fi
  47. function out {
  48. if [ "${QUIET}" != "1" ]; then
  49. echo "$@"
  50. fi
  51. }
  52. # Get file extension
  53. EXT="${FILE##*.}"
  54. if ! [[ "${EXT}" =~ ^(xhtml|xml)$ ]]; then
  55. out "Only works for files ending with .xhtml or .xml"
  56. exit 2
  57. fi
  58. # remove "en.$EXT"
  59. BASE=$(echo "${FILE}" | sed -E "s/\.[a-z][a-z]\.${EXT}//")
  60. # get change date of English file
  61. EN="${BASE}".en."${EXT}"
  62. if [ ! -e "${EN}" ]; then
  63. out "English file does not exist. Aborting. (${EN})"
  64. exit 2
  65. fi
  66. endate=$(git log --pretty="%cd" --date=raw -1 "${EN}"|cut -d' ' -f1)
  67. # check if we have a git log of the EN base file. If not, abort
  68. if [ -z "${endate}" ]; then
  69. out "EN file does not have any Git log. Ususally this means the file is new"
  70. exit 0
  71. fi
  72. # Convert to YYYY-MM-DD
  73. ymd=$(date +"%Y-%m-%d" --date="@$endate")
  74. out "Basefile: ${EN} ( ${ymd} )"
  75. out " STATUS LANG DATE"
  76. out " -------- ---- ----------"
  77. if [ "${ALL}" == "1" ]; then
  78. # Loop over all translations of this file
  79. for i in "${BASE}".[a-z][a-z]."${EXT}"; do
  80. if [[ $i != *".en."* ]]; then
  81. # get language code
  82. lang=$(echo "${i}"|sed "s/.*\.\([a-z][a-z]\)\.${EXT}/\1/")
  83. # get change date of translation
  84. trdate=$(git log --pretty="%cd" --date=raw -1 "${i}"|cut -d' ' -f1)
  85. # Convert to YYYY-MM-DD
  86. ymd=$(date +"%Y-%m-%d" --date="@${trdate}")
  87. # get time difference in seconds
  88. diff=$((trdate-endate))
  89. # mark as outdated if difference larger than 1 hour
  90. if [[ $diff -lt -3600 ]]; then
  91. out " OUTDATED ${lang} ${ymd}"
  92. # print outdated language code
  93. if [ "${ONLY}" == "out" ]; then
  94. echo "${lang}"
  95. fi
  96. else
  97. out " Up-to-date ${lang} ${ymd}"
  98. # print up-to-date language code
  99. if [ "${ONLY}" == "up" ]; then
  100. echo "${lang}"
  101. fi
  102. fi
  103. fi
  104. done | sort
  105. exit 0
  106. else
  107. i="${FILE}"
  108. if [[ $i != *".en."* ]]; then
  109. # get language code
  110. lang=$(echo "${i}"|sed "s/.*\.\([a-z][a-z]\)\.${EXT}/\1/")
  111. # get change date of translation
  112. trdate=$(git log --pretty="%cd" --date=raw -1 "${i}"|cut -d' ' -f1)
  113. # Convert to YYYY-MM-DD
  114. ymd=$(date +"%Y-%m-%d" --date="@${trdate}")
  115. # get time difference in seconds
  116. diff=$((trdate-endate))
  117. # mark as outdated if difference larger than 1 hour
  118. if [[ $diff -lt -3600 ]]; then
  119. out " OUTDATED ${lang} ${ymd}"
  120. exit 1
  121. else
  122. out " Up-to-date ${lang} ${ymd}"
  123. exit 0
  124. fi
  125. else
  126. out " (Comparing status of English file does not make sense)"
  127. fi
  128. fi