-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
update-available-per-app-langs
executable file
·54 lines (47 loc) · 1.46 KB
/
update-available-per-app-langs
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
#!/bin/bash
set -eu
cd "${0%/*}"
langdirs=(app/src/main/res/values-?? app/src/main/res/values-??-r??)
readarray -td '' langdirs < <(printf '%s\0' "${langdirs[@]}" | sort -z)
count_strings() {
code=$1
[[ -n "$code" ]] && code="-$code"
grep -h -c "</string>" "app/src/main/res/values$code/"{strings,preference}.xml "libraries/humla/src/main/res/values$code/strings.xml" \
| awk '{s+=$1} END {print s}'
}
en=$(count_strings "")
declare -a langs
declare -a excluded
for lang in "${langdirs[@]}"; do
lang=${lang##*/}
lang=${lang#values-}
percent=$(( $(count_strings "$lang") * 100 / en ))
if (( percent < 40 )); then
excluded+=("$lang($percent%)")
elif (( percent < 99 )); then
langs+=("$lang($percent%)")
else
langs+=("$lang")
fi
done
printf "included languages: %s\n" "${langs[*]}"
printf "excluded languages: %s\n" "${excluded[*]}"
destf=app/src/main/res/xml/local_config.xml
cat >"$destf" <<-EOF
<?xml version="1.0" encoding="utf-8"?>
<locale-config xmlns:android="http://schemas.android.com/apk/res/android">
EOF
for lang in en-US "${langs[@]}"; do
lang="${lang%%(*}"
printf >>"$destf" ' <locale android:name="%s" />\n' "$lang"
done
printf >>"$destf" "</locale-config>\n"
printf "wrote %s\n" "$destf"
new='resourceConfigurations += ["en"'
for lang in "${langs[@]}"; do
lang="${lang%%(*}"
new=$(printf '%s, "%s"' "$new" "$lang")
done
new="$new]"
sed -i "s/resourceConfigurations .*/$new/" app/build.gradle
printf "updated app/build.gradle\n"