-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstatus.sh
executable file
·118 lines (95 loc) · 3.82 KB
/
status.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# Prints the status, checking for untranslated keys in English.txt and conflicted keys in English.txt
# $1, parameter 1: The destination folder containing the existing translations to check
# $2, parameter 2: The usedkeys.txt file to check against. If you don't have one, use extractused.sh to make one.
# Flags:
# -s sort any files not already sorted
# Example:
# status.sh iap_keys/ usedkeys.txt
# status.sh iap_keys/ usedkeys.txt
# Or perhaps:
# status.sh ../../cig2/Assets/Resources/ ../../cig2/usedkeys.txt
# The empty line above is important, it distinguishes between the usage message (printed) and the code
# If no parameters, print help atop this shell file
if [ -z $1 ]; then
sed -e '/^$/,$d' $0;
exit 1;
fi
if [ -z $2 ]; then
echo "Parameter 2, usedkeys.txt, is mandatory!";
sed -e '/^$/,$d' $0;
exit 1;
fi
# in all scripts, if a folder is passed with trailing /, remove it and continue
inputFolder=`echo $1 | sed 's/\/$//'`;
source langlist.sh
source util.sh
# If the given folder has not yet been rename.sh'ed, rename.sh it and continue
test -e $inputFolder/English.txt
if [ $? -eq 1 ]; then # unable to find English.txt in given folder
ENGLISH_DIR=($inputFolder/"en/");
test -e $ENGLISH_DIR;
if [ $? -eq 0 ]; then
echo "";
rename.sh $inputFolder/
fi
fi
echo "-------Checking formatting---------------";
mkdir -p .internals # Make if not present; because internals/ is .gitignore'd, it will not be present when you checkout
mkdir -p .internals/sortdiff
UNSORTED_FILES=0;
for language in "${ALL_LANGUAGES[@]}"; do
test -e $inputFolder/$language.txt;
if [ $? -gt 0 ]; then
continue; # for sortedness, it is not an error to be missing some files, just ignore them
fi
sort $inputFolder/$language.txt > .internals/$language.txt
diff $inputFolder/$language.txt .internals/$language.txt > .internals/sortdiff/$language.txt
diff_lines .internals/sortdiff/$language.txt;
SORTDIFF_LINES=$?; # store return value of function, since any command (including mv or cp) will write their own return value to the same variable
if [ $SORTDIFF_LINES -gt 0 ]; then
UNSORTED_FILES=1;
printf "%19s is not sorted, %3i lines differ\n" $language $SORTDIFF_LINES;
fi
rm .internals/$language.txt;
rm .internals/sortdiff/$language.txt
done
if [ $UNSORTED_FILES -gt 0 ]; then
echo "Run \`sort.sh $1\` to fix the sorting. Always commit this seperately to any other changes.";
fi
# Check if normalizespaces.sh needs to be run
rm -f .internals/normalizecheckfile.txt
for language in "${ALL_LANGUAGES[@]}"; do
grep " =\|= " $inputFolder/$language.txt >> .internals/normalizecheckfile.txt;
done
abnormalLines=`wc -l .internals/normalizecheckfile.txt | awk {'print $1'}`;
# cut -d' ' -f1 is to get the number before the space, which is the number of lines in the file
if [[ $abnormalLines -gt 0 ]]; then
echo "You need to run \`normalizespaces.sh $1\` to ensure that there are no spaces around the \"=\" character.";
fi
rm -f .internals/normalizecheckfile.txt
echo "-------Checking keys present-------------";
keysmatch.sh $inputFolder/ $2 -s
keysMissing=$?;
if [ $keysMissing -gt 0 ]; then
echo "Run \`keysmatch.sh $1 $2\` for more information about which keys are missing in each file.";
fi
echo "-------Checking for conflicted keys------";
checkunique.sh $inputFolder/ -s
conflictedKeys=$?;
if [ $conflictedKeys -gt 0 ]; then
echo "Run \`checkunique.sh $1\` for more information about which keys are duplicated in each file.";
fi
echo "-------Checking formatstrings------------";
formatstrings.sh $inputFolder/ -s
formatstringError=$?;
if [ $formatstringError -gt 0 ]; then
echo "Run \`formatstrings.sh $1\` for more information about the formatstring errors.";
fi
fatalErrors=$(($keysMissing + $conflictedKeys + $formatstringError));
if [ $fatalErrors -eq 0 ]; then
echo "No fatal errors encountered.";
exit 0;
else
echo "Fix the errors and try again.";
exit 1;
fi