Skip to content

Commit e942ac4

Browse files
committed
Add the script and a sample.
1 parent 9667dea commit e942ac4

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

ios2and.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#! /bin/bash
2+
3+
# print usage if #arg < 4
4+
[ "$#" -lt 4 ] && echo "Usage: ios2and in out prefix postfix"\
5+
&& exit 0
6+
7+
# Android XML string header
8+
# Assume path to $2 exists.
9+
echo "Add $3 to $2"
10+
cp $3 $2
11+
12+
echo "Convert iOS format to XML."
13+
sed 's@^\(".*"\) = "\(.*\)";$@ <string name=\1>\2</string>@g' $1 >> $2
14+
15+
# Must handle '&' first, cause other conversion might contains '&'.
16+
echo "Convert '&' to \"&amp;\""
17+
sed -i.bak 's/&/&amp;/g' $2
18+
19+
echo "Convert '!' to \"&#x21;\""
20+
sed -i.bak 's/!/\&#x21;/g' $2
21+
22+
echo "Convert ''' to \"\\'\""
23+
sed -i.bak "s/'/\\\\'/g" $2
24+
25+
# Delete temp file
26+
rm $2.bak
27+
28+
# Android XML string footer
29+
echo "Add $4 to $2"
30+
cat $4 >> $2
31+

sample/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
android.strings

sample/android.postfix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
<string name="what_ever">As you wish</string>
3+
4+
</resources>
5+

sample/android.prefix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
4+
<string name="android_only_string">Not from iOS</string>
5+

sample/ios.strings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"ios_str1" = "This";
2+
"ios_str2" = "is";
3+
"ios_str3" = "cool!";

sample/run.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#! /bin/bash
2+
../ios2and.sh ios.strings android.strings android.prefix android.postfix

0 commit comments

Comments
 (0)