Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ratana committed Feb 4, 2013
1 parent 7ce53c9 commit ef4db2b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
33 changes: 33 additions & 0 deletions clean_android_strings.py
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:])
33 changes: 33 additions & 0 deletions strings_xml_to_localizable.py
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'&#8230;', '\\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:])

0 comments on commit ef4db2b

Please sign in to comment.