Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- pe=0 # print_error() calls
- petra=0 # translated print_error() calls
- pelit=0 # literal passed in print_error() calls
- me=0 # moodle_exception() calls
- metra=0 # translated moodle_exception calls
- melit=0 # literal passed in moodle_exception() calls
- # Let's use another descriptor different from stdin (that some commands within the loop may consume)
- regexppe="\\\\?print_error"
- regexpex="new +\\\\?moodle_exception"
- while IFS= read -r line <&3
- do
- ispe=
- if [[ "$line" =~ $regexppe ]]; then
- ispe=1
- ((pe++))
- elif [[ "$line" =~ $regexpex ]]; then
- ((me++))
- else
- continue
- fi
- langstr=
- module=
- [[ "$line" =~ [^\']*[\']([^\']+)[\']([^\']+[\']([^\']*)[\'])?|[^\"]*[\"]([^\"]+)[\"]([^\"]+[\"]([^\"]*)[\"])? ]]
- if [[ -n ${BASH_REMATCH[4]} ]]; then
- langstr=${BASH_REMATCH[4]}
- elif [[ -n ${BASH_REMATCH[1]} ]]; then
- langstr=${BASH_REMATCH[1]}
- fi
- if [[ -n ${BASH_REMATCH[6]} ]]; then
- module=${BASH_REMATCH[6]}
- elif [[ -n ${BASH_REMATCH[3]} ]]; then
- module=${BASH_REMATCH[3]}
- fi
- langstr=${BASH_REMATCH[4]:-${BASH_REMATCH[1]}}
- module=${BASH_REMATCH[6]:-${BASH_REMATCH[3]}}
- module=${module#core_}
- if [[ -z "$module" ]] || [[ "$module" == "moodle" ]] || [[ "$module" == "core" ]]; then
- module=error
- fi
- litfound=
- trafound=
- nofound=" STRING NOT FOUND"
- if [[ $langstr =~ ' ' ]]; then
- litfound=" LITERAL FOUND"
- nofound=
- else
- langfiles=$(find . -name "$module.php" | grep '/lang/en/');
- if [[ -n "${langfiles}" ]]; then
- if grep -q "string\['$langstr'\]" $(find . -name "$module.php" | grep '/lang/en/'); then
- trafound=" TRANSLATION FOUND"
- nofound=
- fi
- else
- nofound=" MODULE NOT FOUND"
- fi
- fi
- if [[ -n $ispe ]]; then
- if [[ -n $litfound ]]; then
- ((pelit++))
- elif [[ -n $trafound ]]; then
- ((petra++))
- fi
- else
- if [[ -n $litfound ]]; then
- ((melit++))
- elif [[ -n $trafound ]]; then
- ((metra++))
- fi
- fi
- echo "${nofound}${litfound}${trafound}: $line";
- done 3< <(ag "(new +\\\\?moodle_exception|print_error)\([^'\"\$]*['\"]([^'\"]*)['\"]( *, *['\"]([^'\"]*)['\"])?[^\)\n]*[\)\n]" -o --nofilename --nobreak --php)
- echo "print_error calls: $pe, translated: $petra ($(($petra*100/$pe))%), literals: $pelit ($(($pelit*100/$pe))%)"
- 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