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
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

check-translation-status.sh 3.4KB

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