From ef4db2b7295b4e02c7038441ad11aadbff441f99 Mon Sep 17 00:00:00 2001 From: Adam Ratana Date: Mon, 4 Feb 2013 02:21:35 -0500 Subject: [PATCH] initial commit --- clean_android_strings.py | 33 +++++++++++++++++++++++++++++++++ strings_xml_to_localizable.py | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 clean_android_strings.py create mode 100644 strings_xml_to_localizable.py diff --git a/clean_android_strings.py b/clean_android_strings.py new file mode 100644 index 0000000..358adf9 --- /dev/null +++ b/clean_android_strings.py @@ -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'\"?', '\"', 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: ' + sys.exit(2) + clean_android_strings(sys.argv[1], sys.argv[2]) + +if __name__ == "__main__": + main(sys.argv[1:]) \ No newline at end of file diff --git a/strings_xml_to_localizable.py b/strings_xml_to_localizable.py new file mode 100644 index 0000000..798c267 --- /dev/null +++ b/strings_xml_to_localizable.py @@ -0,0 +1,33 @@ +import sys +import re + +def transform_android_string(android_string): + transformed = re.sub(r'(?:\"?', '\" = \"', transformed) + transformed = re.sub(r'\"?', '\";', transformed) + transformed = re.sub(r'', '*/', transformed) + transformed = re.sub(r'', '', transformed) #strip resource tags + transformed = re.sub(r'', '', 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: ' + sys.exit(2) + convert_android_to_ios(sys.argv[1], sys.argv[2]) + +if __name__ == "__main__": + main(sys.argv[1:]) \ No newline at end of file