forked from 1stsetup/exchangecalendar
-
Notifications
You must be signed in to change notification settings - Fork 112
/
translationupdater.sh
executable file
·210 lines (167 loc) · 4.81 KB
/
translationupdater.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/bin/bash
declare -a LOCALEFILES
declare -a LOCALEFOLDERS
declare -a ELOG
ECOUNT=0
LOCALEROOT=""
LOCALEFILESCOUNT=0
LOCALEFOLDERSCOUNT=0
LOCALEROOT=""
ENUSFOLDERPATH=""
function IsFolder(){
DIR=$1
[ -d $DIR ] && [ -n $DIR ] && echo "true" || echo "false"
}
function IsFile(){
FILE=$1
[ -f $FILE ] && [ -n $FILE ] && echo "true" || echo "false"
}
function LogLine(){
[ -n "$1" ] &&echo -en "\n$1"
}
function LogError(){
echo -en "\nERROR:- $1."
echo -en "\n"
exit 1
}
function GetLocaleFolder(){
if [ "$(IsFolder $LOCALEROOT)" = "false" ];then
LogError "Not a valid locale folder"
fi
LOCALEFOLDERS=( $( find $LOCALEROOT -maxdepth 1 -type d | sed "s|^$LOCALEROOT/||" ) )
}
function GetEnUsFiles(){
if [ "$(IsFolder $ENUSFOLDERPATH)" = "false" ];then
LogError "Locale(en-US) Path is not valid"
fi
LOCALEFILES=( $( find $ENUSFOLDERPATH -type f -name "*.dtd" | sed "s|^$ENUSFOLDERPATH/||" ) )
}
function CopyMissingFiles(){
LogLine "\n**Copying missing files from en-Us"
stage=0
#loop each locale folder
for FLDR in "${LOCALEFOLDERS[@]}"
do
MissingCount=0
TEMPFOLDER=""
TEMPFOLDER="$LOCALEROOT/$FLDR"
[ $LOCALEROOT = "$FLDR" ] && continue
[ $TEMPFOLDER = $ENUSFOLDERPATH ] && continue
[ "$( IsFolder $TEMPFOLDER)" = "false" ] && continue
LogLine "\n[$((++stage))]Checking for missing files in Locale Folder $FLDR"
#loop each file in en-us folder with others
for FLS in "${LOCALEFILES[@]}"
do
TEMPFILE=""
TEMPFILE="$TEMPFOLDER/$FLS"
ENFILE=""
ENFILE=$ENUSFOLDERPATH/$FLS
if [ "$(IsFile $TEMPFILE)" = "true" ];then
:
else
((MissingCount++))
#lets copy the missing files
status="fail"
cp "$ENFILE" "$TEMPFILE"
if [ $? -eq 0 ];then
status="success"
fi
ELOG[$((ECOUNT++))]="cp: $ENFILE --> $TEMPFILE -- $status"
fi
done
[ $MissingCount -gt 0 ] && LogLine "MissingCount: $MissingCount"
done
}
function CopyMissingTranslation(){
LogLine "\n**Copying missing tranlation from en-Us files"
stage=0
#loop each locale folder
for FLDR in "${LOCALEFOLDERS[@]}"
do
TEMPFOLDER=""
TEMPFOLDER="$LOCALEROOT/$FLDR"
[ $LOCALEROOT = "$FLDR" ] && continue
[ $TEMPFOLDER = $ENUSFOLDERPATH ] && continue
[ "$( IsFolder $TEMPFOLDER)" = "false" ] && continue
LogLine "\n[$((++stage))]Checking for missing translation in Locale Folder $FLDR"
#loop each file in en-us folder with others
for FLS in "${LOCALEFILES[@]}"
do
TEMPFILE=""
TEMPFILE="$TEMPFOLDER/$FLS"
ENFILE=""
ENFILE=$ENUSFOLDERPATH/$FLS
if [ "$(IsFile $TEMPFILE)" = "true" ];then
#process one file in en-Us at a time with current locale folder
declare -a ENLINE
MissingCount=0
while read ENLINE
do
#convert line to array
declare -a LINEARR=(`echo "$ENLINE"`)
#we know that fild 1 is identifier in dtd file
IDENTIFIER=${LINEARR[1]}
grep "$IDENTIFIER" "$TEMPFILE" >/dev/null
if [ $? -eq 0 ];then
:
else
((MissingCount++))
#lets copy the missing files
status="fail"
echo "$ENLINE" >> $TEMPFILE
if [ $? -eq 0 ];then
status="success"
fi
ELOG[$((ECOUNT++))]="+>> $IDENTIFIER --> $TEMPFILE -- $status"
fi
done<$ENFILE
[ $MissingCount -gt 0 ] && LogLine "$TEMPFILE\nMissingCount: $MissingCount"
else
:
fi
done
done
}
function ExtaLog(){
LogLine "\n**More Logs:"
for Line in "${ELOG[@]}"
do
LogLine "$Line"
done
}
#Propmt for path
ROOT=$1
[ $# -lt 1 ] && LogError "Input Required. Exit"
if [ "$(IsFolder $ROOT)" = "false" ];then
LogError "Folder \"$ROOT\" is invalid"
fi
LogLine "ROOT Set to $ROOT"
LOCALEROOT="$ROOT/locale/exchangecalendar"
LogLine "Locale Path: $LOCALEROOT"
ENUSFOLDERPATH="$LOCALEROOT/en-US"
LogLine "en-US Locale Path: $ENUSFOLDERPATH"
#GetLocaleFolder
GetLocaleFolder
LOCALEFOLDERSCOUNT=${#LOCALEFOLDERS[@]}
#echo -en "c" ${#LOCALEFOLDERS[@]} ${LOCALEFOLDERS[@]}
if [ ${#LOCALEFOLDERSCOUNT[@]} -lt 1 ] ; then
LogError "Locale Folder not found"
fi
GetEnUsFiles
LOCALEFILESCOUNT=${#LOCALEFILES[@]}
#echo -en "c" ${#LOCALEFILES[@]} ${LOCALEFILES[@]}
if [ ${#LOCALEFILESCOUNT[@]} -lt 1 ] ; then
LogError "Locale files not found"
fi
#lets copy missing locale file in other folders from en-Us
CopyMissingFiles
#lets copy missing locale translation to other files from en-Us
CopyMissingTranslation
if [ ${#ELOG[@]} -gt 0 ] ; then
LogLine ""
read -n 1 -p 'Do you see extra logs [y/N?]' REPLY
[ "$REPLY" = "y" ] && ExtaLog
LogLine "\n--->Log Wrtitten to /tmp/ExtraLog"
echo -en "${ELOG[@]} " > /tmp/ExtraLog
fi
echo -ne "\n"