-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_plurals
executable file
·126 lines (110 loc) · 3.41 KB
/
merge_plurals
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
#!/bin/bash
# Copyright (c) 2015, Redmaner
# Define bash colors for Mac OSX / Linux
case `uname -s` in
Darwin)
txtrst='\033[0m' # Color off
txtred='\033[0;31m' # Red
txtgrn='\033[0;32m' # Green
txtblu='\033[0;34m' # Blue
;;
*)
txtrst='\e[0m' # Color off
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtblu='\e[0;36m' # Blue
;;
esac
up=$PWD
MergePlurals () {
mkdir -p $new_plural_dir
grep '<plurals' $orig_plural | uniq --unique | while read plural; do
plural_type=$(echo $plural | cut -d'<' -f2 | cut -d' ' -f1)
plural_name=$(echo $plural | cut -d'"' -f2)
if [ $(sed -e '/name="'$plural_name'"/!d' $targ_plural | wc -l) -gt 0 ]; then
if [ $(sed -e '/name="'$plural_name'"/!d' $targ_plural | grep '/>' | wc -l) -gt 0 ]; then
sed -e '/<'$plural_type' name="'$plural_name'"/!d' $targ_plural >> $new_plural; continue
else
sed -e '/<'$plural_type' name="'$plural_name'"/,/'$plural_type'>/!d' $targ_plural >> $new_plural; continue
fi
else
if [ $(sed -e '/name="'$plural_name'"/!d' $orig_plural | grep '/>' | wc -l) -gt 0 ]; then
sed -e '/<'$plural_type' name="'$plural_name'"/!d' $orig_plural >> $new_plural; continue
else
sed -e '/<'$plural_type' name="'$plural_name'"/,/'$plural_type'>/!d' $orig_plural >> $new_plural; continue
fi
fi
done
if [ "$dual_merge" == true ]; then
grep '<plurals' $orig_plural_second | uniq --unique | while read plural; do
plural_type=$(echo $plural | cut -d'<' -f2 | cut -d' ' -f1)
plural_name=$(echo $plural | cut -d'"' -f2)
if [ $(sed -e '/name="'$plural_name'"/!d' $orig_plural | wc -l) -gt 0 ]; then
continue
elif [ $(sed -e '/name="'$plural_name'"/!d' $targ_plural | wc -l) -gt 0 ]; then
if [ $(sed -e '/name="'$plural_name'"/!d' $targ_plural | grep '/>' | wc -l) -gt 0 ]; then
sed -e '/<'$plural_type' name="'$plural_name'"/!d' $targ_plural >> $new_plural; continue
else
sed -e '/<'$plural_type' name="'$plural_name'"/,/'$plural_type'>/!d' $targ_plural >> $new_plural; continue
fi
else
if [ $(sed -e '/name="'$plural_name'"/!d' $orig_plural_second | grep '/>' | wc -l) -gt 0 ]; then
sed -e '/<'$plural_type' name="'$plural_name'"/!d' $orig_plural_second >> $new_plural; continue
else
sed -e '/<'$plural_type' name="'$plural_name'"/,/'$plural_type'>/!d' $orig_plural_second >> $new_plural; continue
fi
fi
done
fi
if [ -s $new_plural ]; then
echo -e "<?xml version='1.0' encoding='UTF-8'?>\n<resources>" > $new_plural_final
cat $new_plural >> $new_plural_final
echo '</resources>' >> $new_plural_final
rm -f $new_plural
echo -e "${txtblu}>> Merged ${txtgrn}plurals${txtrst} $apk_file to $new_plural_final"
fi
}
ShowHelp () {
echo -e "
Script requires three arguments
First argument: path to original plurals.xml
Second argument: path to target plurals.xml
Third argument: path to new plurals.xml
Fourth argument: apk name
"
exit
}
if [ -f "$1" ]; then
orig_plural=$1
else
ShowHelp; exit
fi
if [ -f "$2" ]; then
targ_plural=$2
else
ShowHelp; exit
fi
if [ "$3" != "" ]; then
new_plural=$3.new
new_plural_final=$3
new_plural_dir=$(dirname $new_plural)
else
ShowHelp; exit
fi
if [ "$4" != "" ]; then
apk_file=$4
else
ShowHelp; exit
fi
if [ "$5" != "" ]; then
untranslateable_list=$5
else
untranslateable_list=undefined
fi
if [ "$6" != "" ]; then
dual_merge=$6
fi
if [ "$7" != "" ]; then
orig_plural_second=$7
fi
MergePlurals