Advertisement
stronk7

Untitled

Mar 2nd, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. pe=0 # print_error() calls
  4. petra=0 # translated print_error() calls
  5. pelit=0 # literal passed in print_error() calls
  6. me=0 # moodle_exception() calls
  7. metra=0 # translated moodle_exception calls
  8. melit=0 # literal passed in moodle_exception() calls
  9.  
  10. # Let's use another descriptor different from stdin (that some commands within the loop may consume)
  11.  
  12. regexppe="\\\\?print_error"
  13. regexpex="new +\\\\?moodle_exception"
  14.  
  15. while IFS= read -r line <&3
  16. do
  17. ispe=
  18. if [[ "$line" =~ $regexppe ]]; then
  19. ispe=1
  20. ((pe++))
  21. elif [[ "$line" =~ $regexpex ]]; then
  22. ((me++))
  23. else
  24. continue
  25. fi
  26.  
  27. langstr=
  28. module=
  29. [[ "$line" =~ [^\']*[\']([^\']+)[\']([^\']+[\']([^\']*)[\'])?|[^\"]*[\"]([^\"]+)[\"]([^\"]+[\"]([^\"]*)[\"])? ]]
  30. if [[ -n ${BASH_REMATCH[4]} ]]; then
  31. langstr=${BASH_REMATCH[4]}
  32. elif [[ -n ${BASH_REMATCH[1]} ]]; then
  33. langstr=${BASH_REMATCH[1]}
  34. fi
  35. if [[ -n ${BASH_REMATCH[6]} ]]; then
  36. module=${BASH_REMATCH[6]}
  37. elif [[ -n ${BASH_REMATCH[3]} ]]; then
  38. module=${BASH_REMATCH[3]}
  39. fi
  40. langstr=${BASH_REMATCH[4]:-${BASH_REMATCH[1]}}
  41. module=${BASH_REMATCH[6]:-${BASH_REMATCH[3]}}
  42.  
  43. module=${module#core_}
  44. if [[ -z "$module" ]] || [[ "$module" == "moodle" ]] || [[ "$module" == "core" ]]; then
  45. module=error
  46. fi
  47.  
  48. litfound=
  49. trafound=
  50. nofound=" STRING NOT FOUND"
  51.  
  52. if [[ $langstr =~ ' ' ]]; then
  53. litfound=" LITERAL FOUND"
  54. nofound=
  55. else
  56. langfiles=$(find . -name "$module.php" | grep '/lang/en/');
  57. if [[ -n "${langfiles}" ]]; then
  58. if grep -q "string\['$langstr'\]" $(find . -name "$module.php" | grep '/lang/en/'); then
  59. trafound=" TRANSLATION FOUND"
  60. nofound=
  61. fi
  62. else
  63. nofound=" MODULE NOT FOUND"
  64. fi
  65. fi
  66.  
  67. if [[ -n $ispe ]]; then
  68. if [[ -n $litfound ]]; then
  69. ((pelit++))
  70. elif [[ -n $trafound ]]; then
  71. ((petra++))
  72. fi
  73. else
  74. if [[ -n $litfound ]]; then
  75. ((melit++))
  76. elif [[ -n $trafound ]]; then
  77. ((metra++))
  78. fi
  79. fi
  80.  
  81. echo "${nofound}${litfound}${trafound}: $line";
  82.  
  83. done 3< <(ag "(new +\\\\?moodle_exception|print_error)\([^'\"\$]*['\"]([^'\"]*)['\"]( *, *['\"]([^'\"]*)['\"])?[^\)\n]*[\)\n]" -o --nofilename --nobreak --php)
  84.  
  85. echo "print_error calls: $pe, translated: $petra ($(($petra*100/$pe))%), literals: $pelit ($(($pelit*100/$pe))%)"
  86. echo "new moodle_exception calls: $me, translated: $metra ($(($metra*100/$me))%), literals: $melit ($(($melit*100/$me))%)"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement