SchildiChat-android/correct_strings.sh

77 lines
2.8 KiB
Bash
Raw Permalink Normal View History

2020-07-25 11:02:44 +03:00
#!/bin/bash
set -e
2020-07-25 11:02:44 +03:00
mydir="$(dirname "$(realpath "$0")")"
source "$mydir/merge_helpers.sh"
2020-07-25 11:02:44 +03:00
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 \
2020-07-25 11:02:44 +03:00
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 \
2020-07-25 11:02:44 +03:00
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' '{}' \;
2020-07-25 11:02:44 +03:00
unpatched_strings_file=.tmp_unpatched_strings
new_patched_strings_file=.tmp_new_patched_strings
patch_file_updated=0
2020-07-25 11:02:44 +03:00
# 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 :)"