=== modified file 'resources/util/clean_translations.sh' --- resources/util/clean_translations.sh 2012-09-20 13:14:12 +0000 +++ resources/util/clean_translations.sh 2012-09-26 20:25:15 +0000 @@ -1,6 +1,8 @@ #!/bin/bash #This script should clean all translation files in a given directory -#removing all non-translated keys, and any legacy keys in the translation files. +#removing all non-translated keys, and any legacy keys in the translation fi + + isNotSet() { if [[ ! ${!1} && ${!1-_} ]] then @@ -12,27 +14,35 @@ echo "Usage: $0 directory" exit 1 fi +#Parse the arguments +TRANS_REGEX="i18n_*_*.properties" +while getopts ":l:" opt; do + case $opt in + l) TRANS_REGEX="i18n_*_"$OPTARG".properties";; + \?) print >&2 "Usage: $0 [-l language_country] directory ..." + exit 1;; + esac +done +shift $(($OPTIND-1)) DIR=$1 #The directory should be the first argument -#TODO Test the directories are writable # save and change IFS OLDIFS=$IFS IFS=$'\n' -fileArray=($(find $DIR -type f -name "i18n_*_*.properties")) +fileArray=($(find $DIR -type f -name $TRANS_REGEX)) -# restore it +# restore IFS IFS=$OLDIFS -# get length of the files to iterate over +# get length of the translation files tLen=${#fileArray[@]} #Find the template file TEMPLATE=($(find $DIR -name 'i18n*.properties' -type f | grep -P "i18n_(module|global).properties")) TEMPLATE_OUT="$(mktemp)" -grep -Ev '^#' $TEMPLATE | sed '/^\r/d' | grep -Ev '^$'| sort > $TEMPLATE_OUT - +grep -Ev '^#' $TEMPLATE | sed '/^\r/d' | grep -Ev '^$' > $TEMPLATE_OUT declare -A template_array while IFS='=' read -r key val; do [[ $key = '#'* ]] && continue @@ -44,8 +54,7 @@ declare -A trans_array TRANS_FILE=${fileArray[$i]} - TRANS_OUT="$(mktemp)" - #make a backup copy + TRANS_OUT="$(mktemp)" cp $TRANS_FILE $TRANS_FILE.bak grep -Ev '^#' $TRANS_FILE | sed '/^\r/d' | grep -Ev '^$'| sort > $TRANS_OUT @@ -58,7 +67,7 @@ for key in "${!template_array[@]}"; do - isNotSet trans_array[${key}] + isNotSet trans_array[${key}] if [ $? -ne 1 ];then translation=${trans_array[$key]} template=${template_array[$key]} @@ -71,6 +80,4 @@ rm $TRANS_OUT unset trans_array done - rm $TEMPLATE_OUT -