← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8157: (Translations) Adapt script to clean all translation files in a given directory.

 

------------------------------------------------------------
revno: 8157
committer: root <root@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-09-20 10:26:44 +0000
message:
  (Translations) Adapt script to clean all translation files in a given directory.
modified:
  resources/util/clean_translations.sh


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'resources/util/clean_translations.sh'
--- resources/util/clean_translations.sh	2012-09-20 07:49:50 +0000
+++ resources/util/clean_translations.sh	2012-09-20 10:26:44 +0000
@@ -1,4 +1,6 @@
 #!/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.
 isNotSet() {
     if [[ ! ${!1} && ${!1-_} ]]
     then
@@ -6,48 +8,69 @@
     fi
 }
 
-
 if [[ $# -lt 1 ]]; then
-  echo "Usage: $0 original-properties-file translation-properties-file"
+  echo "Usage: $0  directory"
   exit 1
 fi
 
+DIR=$1 #The directory should be the first argument
+
+# failsafe - fall back to current directory
+[ "$DIR" == "" ] && DIR="."
+
+# save and change IFS
+OLDIFS=$IFS
+IFS=$'\n'
+
+fileArray=($(find $DIR -type f -name "i18n_*_*.properties"))
+
+# restore it
+IFS=$OLDIFS
+
+# get length of an array
+tLen=${#fileArray[@]}
+
+#Find the template file
+TEMPLATE=($(find $DIR -name 'i18n*.properties' -type f | grep -P "i18n_(module|global).properties"))
+
+grep -Ev '^#' $TEMPLATE | sed '/^\r/d' | grep -Ev '^$'| sort > tmpfile1
 declare -A array1
-declare -A array2
-PROP_FILE=$2
-
-cp $2 $2.bak
-grep -Ev '^#' $1 | sed '/^\r/d' | grep -Ev '^$'| sort > tmpfile1
-grep -Ev '^#' $2 | sed '/^\r/d' | grep -Ev '^$'| sort > tmpfile2
-
 while IFS='=' read -r key val; do
         [[ $key = '#'* ]] && continue
         array1["$key"]="$val"
 done < tmpfile1
 
-
-while IFS='=' read -r key val; do
+for (( i=0; i<${tLen}; i++ ));
+	do
+
+	declare -A array2
+	PROP_FILE=${fileArray[$i]}
+
+	cp $PROP_FILE $PROP_FILE.bak
+	grep -Ev '^#' $PROP_FILE | sed '/^\r/d' | grep -Ev '^$'| sort > tmpfile2
+
+	while IFS='=' read -r key val; do
         [[ $key = '#'* ]] && continue
         array2["$key"]="$val"
-done < tmpfile2
-
-echo -n "" > $2
-
-for key in "${!array1[@]}"; do
-
-isNotSet array2[${key}]
-
-if [ $? -ne 1  ];then
-
-value2=${array2[$key]}
-value1=${array1[$key]}
-
-if [[ *"$value1"* != *"$value2"* ]];then
-echo "$key=${array2[$key]}" >> ${PROP_FILE};
-fi
-fi
+	done < tmpfile2
+
+	echo -n "" > $PROP_FILE
+
+	for key in "${!array1[@]}"; do
+
+	isNotSet array2[${key}]
+	if [ $? -ne 1  ];then
+		value2=${array2[$key]}
+		value1=${array1[$key]}
+		if [[ *"$value1"* != *"$value2"* ]];then
+			echo "$key=${array2[$key]}" >> ${PROP_FILE};
+		fi
+	fi
+	done
+
+rm tmpfile2
+unset array2
+echo ${#array2[@]}
 done
 
 rm tmpfile1
-rm tmpfile2
-