Skip to content

Commit ba831b3

Browse files
committed
chore: update localize script to support grabbing android only strings
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 34a56af commit ba831b3

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

scripts/localize.sh

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ function traverse_and_clean {
3232
ruby "${root}"/scripts/convert-strings.rb $fileName
3333
rm "$fileName"
3434
# grab access key android value and replace iOS
35-
androidValue=$(xmlstarlet sel -t -v '//string[@name="subtitle.accessKeySnapshotDescriptionAndroid"]' strings.xml)
36-
xmlstarlet ed -L -u '//string[@name="subtitle_accessKeySnapshotDescription"]' -v "$androidValue" strings-localized.xml
35+
grab_android_string "subtitle.accessKeySnapshotDescriptionAndroid" "subtitle_accessKeySnapshotDescription"
3736
rm strings.xml
3837
cd - || exit
3938
fi
@@ -73,6 +72,31 @@ function traverse_and_clean {
7372
done
7473
}
7574

75+
function grab_android_string {
76+
androidStringName=$1
77+
if [ -z "$2" ]; then
78+
replaceWith=${androidStringName//./_}
79+
else
80+
replaceWith=$2
81+
fi
82+
83+
# Fetch the value for the provided androidStringName from strings.xml
84+
androidValue=$(xmlstarlet sel -t -v "//string[@name=\"$androidStringName\"]" strings.xml)
85+
86+
# Check if the string exists in strings-localized.xml
87+
stringExists=$(xmlstarlet sel -t -v "count(//string[@name=\"$replaceWith\"])" strings-localized.xml)
88+
89+
if [ "$stringExists" -eq 0 ]; then
90+
# If the string does not exist, add it
91+
xmlstarlet ed -L -s "/resources" -t elem -n "string" -v "$androidValue" \
92+
-i "//string[not(@name)]" -t attr -n "name" -v "$replaceWith" \
93+
strings-localized.xml
94+
else
95+
# If the string exists, update its value
96+
xmlstarlet ed -L -u "//string[@name=\"$replaceWith\"]" -v "$androidValue" strings-localized.xml
97+
fi
98+
}
99+
76100
function copy_strings {
77101
for dir in "$1"/*
78102
do

0 commit comments

Comments
 (0)