Skip to content

Instantly share code, notes, and snippets.

@satanasov
Created September 5, 2016 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satanasov/3b616b7283dc73f3296b03524778e9e8 to your computer and use it in GitHub Desktop.
Save satanasov/3b616b7283dc73f3296b03524778e9e8 to your computer and use it in GitHub Desktop.
#!/bin/bash
# A quick script to check language usage in phpBB extension
# Author: Stanislav Atanasov (lucifer@anavar.com
# Script provided as is!
VARIABLES=( "$@" )
LANG_FILE=''
TARGET_EXT=''
FULL=0
count=0
while [ "x${VARIABLES[count]}" != x ]; do
if [[ ${VARIABLES[count]} == "-l" ]] || [[ ${VARIABLES[count]} == "--language" ]]; then
count=$(( $count + 1 ))
LANG_FILE=${VARIABLES[count]}
count=$(( $count + 1))
elif [[ ${VARIABLES[count]} == "-t" ]] || [[ ${VARIABLES[count]} == "--target" ]]; then
count=$(( $count + 1 ))
TARGET_EXT=${VARIABLES[count]}
count=$(( $count + 1))
elif [[ ${VARIABLES[count]} == "-f" ]] || [[ ${VARIABLES[count]} == "--full" ]]; then
count=$(( $count + 1 ))
FULL=1
fi
done
if [[ ! $LANG_FILE ]] || [[ ! $TARGET_EXT ]]; then
printf "Usage:
-l, --language {TARGET} - Select desired language file
-t, --target {EXT} - Select the target extension directory
-f - Show full report where the language variables are used
WARNING: The script will use the target for building the report and will skip language folder \n"
elif [[ ! -e $LANG_FILE ]]; then
printf "Language file $LANG_FILE doesn't exist. Please check again!\n"
elif [[ ! -d $TARGET_EXT ]]; then
printf "Extension $TARGET_EXT doesn't exist. Please check again!\n"
else
while read -r line || [[ -n "$line" ]]; do
fstr=`echo $line| cut -c1`
if [[ $fstr ]] && [[ $fstr == *"'"* ]]; then
str=`echo $line | awk '{print $1}'`
if [[ $FULL == 1 ]]; then
echo $str
grep -Rni --exclude-dir=language "$str" $TARGET_EXT
else
count=`grep -Rni --exclude-dir=language "$str" $TARGET_EXT | wc -l`
echo "$str -> $(($count))"
fi
fi
done < "$LANG_FILE"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment