-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sys | ||
import re | ||
|
||
def clean_android_string(android_string): | ||
#\\" -> \" | ||
transformed = re.sub(r'\\\\"', '\\"', android_string) | ||
#... -> ellipse | ||
transformed = re.sub(r'\.\.\.', '…', transformed) | ||
#trim whitespace around \n | ||
transformed = re.sub(r'\s*\\n\s*', re.escape('\\') + 'n', transformed) | ||
#place quotes around strings inside xml tags that do not have them | ||
transformed = re.sub(r'\"?</string>', '\"</string>', transformed) | ||
transformed = re.sub(r'">"?', '">"', transformed) | ||
return transformed | ||
|
||
def clean_android_strings(input_file_name, output_file_name): | ||
inputfile = open(input_file_name,'r') | ||
outputfile = open(output_file_name, 'w') | ||
outputfile.write(clean_android_string(inputfile.read())) | ||
outputfile.close() | ||
inputfile.close() | ||
|
||
# Very simple tool to cleanup an android strings.xml file | ||
def main(argv): | ||
num_args = len(sys.argv) | ||
if num_args != 3: | ||
print 'Cleans an Android strings.xml' | ||
print 'Usage: <input.xml> <output.xml>' | ||
sys.exit(2) | ||
clean_android_strings(sys.argv[1], sys.argv[2]) | ||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import sys | ||
import re | ||
|
||
def transform_android_string(android_string): | ||
transformed = re.sub(r'(?:<string name=\"|<string name = \")', '\"', android_string) #convert string tags | ||
transformed = re.sub(r'\">\"?', '\" = \"', transformed) | ||
transformed = re.sub(r'\"?</string>', '\";', transformed) | ||
transformed = re.sub(r'<!--', '/*', transformed) #convert xml comments | ||
transformed = re.sub(r'-->', '*/', transformed) | ||
transformed = re.sub(r'<resources>', '', transformed) #strip resource tags | ||
transformed = re.sub(r'</resources>', '', transformed) | ||
transformed = re.sub(r'…', '\\U2026', transformed) #convert xml entity ellipse to unicode | ||
return transformed | ||
|
||
def convert_android_to_ios(input_file_name, output_file_name): | ||
inputfile = open(input_file_name,'r') | ||
outputfile = open(output_file_name, 'w') | ||
outputfile.write(transform_android_string(inputfile.read())) | ||
outputfile.close() | ||
inputfile.close() | ||
|
||
# Very simple tool to convert an android strings.xml file to an iOS Localizable.strings file | ||
# This does not currently handle complex android strings | ||
def main(argv): | ||
num_args = len(sys.argv) | ||
if num_args != 3: | ||
print 'Converts an Android strings.xml to an iOS Localizable.strings' | ||
print 'Usage: <input.xml> <output.strings>' | ||
sys.exit(2) | ||
convert_android_to_ios(sys.argv[1], sys.argv[2]) | ||
|
||
if __name__ == "__main__": | ||
main(sys.argv[1:]) |