forked from element-hq/element-android
-
Notifications
You must be signed in to change notification settings - Fork 60
/
correct_strings.sh
executable file
·76 lines (62 loc) · 2.81 KB
/
correct_strings.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
#!/bin/bash
set -e
mydir="$(dirname "$(realpath "$0")")"
source "$mydir/merge_helpers.sh"
pushd "$mydir" > /dev/null
# Require clean git state
uncommitted=`git status --porcelain`
if [ ! -z "$uncommitted" ]; then
echo "Uncommitted changes are present, please commit first!"
exit 1
fi
mydir="."
stringdir="$mydir/library/ui-strings/src/main/res"
# Element -> SchildiChat
find "$stringdir" -name strings.xml -exec \
sed -i 's|Element|SchildiChat|g' '{}' \;
# Restore Element where it makes sense
find "$stringdir" -name strings.xml -exec \
sed -i 's/SchildiChat \(Web\|iOS\|Desktop\)/Element \1/g' '{}' \;
find "$stringdir" -name strings.xml -exec \
sed -i 's|SchildiChat Matrix Services|Element Matrix Services|g' '{}' \;
find "$stringdir" -name strings.xml -exec \
sed -i 's|\("use_latest_riot">.*\)SchildiChat\(.*</string>\)|\1Element\2|g' '{}' \;
find "$stringdir" -name strings.xml -exec \
sed -i 's|\("use_other_session_content_description">.*\)SchildiChat\(.*SchildiChat.*</string>\)|\1SchildiChat/Element\2|' '{}' \;
find "$stringdir" -name strings.xml -exec \
sed -i 's/SchildiChat\( \|-\)Call/Element\1Call/g' '{}' \;
unpatched_strings_file=.tmp_unpatched_strings
new_patched_strings_file=.tmp_new_patched_strings
patch_file_updated=0
# Requires manual intervention for correct grammar
#for strings_de in "$stringdir/values-de/strings.xml" "$mydir/matrix-sdk-android/src/main/res/values-de/strings.xml"; do
for strings_de in "$stringdir/values-de/strings.xml"; do
echo "Apply known language fixes to $strings_de..."
source ./correct_strings_de.sh
while grep -q "wolpertinger\|schlumpfwesen" "$strings_de"; do
grep "wolpertinger\|schlumpfwesen" "$strings_de" | sed "s|.*>\\(.*\\)<.*|\1|" > "$unpatched_strings_file"
echo "Unpatched strings discovered, please shorten detection strings as appropriate:"
await_edit "$unpatched_strings_file"
cp "$unpatched_strings_file" "$new_patched_strings_file"
echo "Now enter the patched strings:"
await_edit "$new_patched_strings_file"
echo "Rewriting patch file..."
while read old_str <&3 && read new_str <&4; do
echo "sed -i 's|$old_str|$new_str|g' \"\$strings_de\"" >> ./correct_strings_de.sh
done 3<"$unpatched_strings_file" 4<"$new_patched_strings_file"
rm "$unpatched_strings_file" "$new_patched_strings_file"
echo "Re-applying language fix..."
source ./correct_strings_de.sh
patch_file_updated=1
done
done
if ((patch_file_updated)); then
git add ./correct_strings_de.sh
git commit -m "Update string correction"
fi
# Remove Triple-T stuff to avoid using them in F-Droid
rm -rf "$mydir/vector/src/main/play/listings"
git add -A
git commit -m "Automatic SchildiChat string correction"
popd > /dev/null
echo "Seems like language is up-to-date :)"