File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
76100function copy_strings {
77101 for dir in " $1 " /*
78102 do
You can’t perform that action at this time.
0 commit comments