Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.