| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 # Usage: generate_localizer [xib_path] [output_dot_h_path] [output_dot_mm_path] | 7 # Usage: generate_localizer [xib_path] [output_dot_h_path] [output_dot_mm_path] |
| 8 # | 8 # |
| 9 # Extracts all the localizable strings that start with "^IDS" from the given | 9 # Extracts all the localizable strings that start with "^IDS" from the given |
| 10 # xib file, and then generates a localizer to process those strings. | 10 # xib file, and then generates a localizer to process those strings. |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 plist_string = xib_localizable_strings(xib_path) | 138 plist_string = xib_localizable_strings(xib_path) |
| 139 if not plist_string: | 139 if not plist_string: |
| 140 return 2 | 140 return 2 |
| 141 plist = plistlib.readPlistFromString(plist_string) | 141 plist = plistlib.readPlistFromString(plist_string) |
| 142 | 142 |
| 143 # Extract the resource constant strings | 143 # Extract the resource constant strings |
| 144 localizable_strings = plist['com.apple.ibtool.document.localizable-strings'] | 144 localizable_strings = plist['com.apple.ibtool.document.localizable-strings'] |
| 145 constants_list = extract_resource_constants(localizable_strings, xib_path) | 145 constants_list = extract_resource_constants(localizable_strings, xib_path) |
| 146 if not constants_list: | 146 if not constants_list: |
| 147 sys.stderr.write("%s:0: warning: %s didn't find any resource strings\n" % | 147 sys.stderr.write("%s:0: warning: %s didn't find any resource strings\n" % |
| 148 xib_path, generate_localizer); | 148 (xib_path, generate_localizer)); |
| 149 # Seed constant_list with an entry so things will compile even though the |
| 150 # array sould really be empty (array_size in the generated file doesn't |
| 151 # like an empty array). |
| 152 constants_list.append('^0'); |
| 149 | 153 |
| 150 # Name the class based on the output file | 154 # Name the class based on the output file |
| 151 class_name = os.path.splitext(os.path.basename(output_h_path))[0] | 155 class_name = os.path.splitext(os.path.basename(output_h_path))[0] |
| 152 suffix = '_localizer' | 156 suffix = '_localizer' |
| 153 if class_name.endswith(suffix): | 157 if class_name.endswith(suffix): |
| 154 class_name = class_name[:-len(suffix)]; | 158 class_name = class_name[:-len(suffix)]; |
| 155 class_name = class_name.replace('_', ' ').title().replace(' ', ''); | 159 class_name = class_name.replace('_', ' ').title().replace(' ', ''); |
| 156 | 160 |
| 157 # Generate our file contents | 161 # Generate our file contents |
| 158 (h_file_content, mm_file_content) = \ | 162 (h_file_content, mm_file_content) = \ |
| 159 generate_files_contents(class_name, constants_list, | 163 generate_files_contents(class_name, constants_list, |
| 160 os.path.basename(output_h_path), | 164 os.path.basename(output_h_path), |
| 161 xib_path) | 165 xib_path) |
| 162 | 166 |
| 163 # Write out the files | 167 # Write out the files |
| 164 file_fd = open(output_h_path, 'w') | 168 file_fd = open(output_h_path, 'w') |
| 165 file_fd.write(h_file_content) | 169 file_fd.write(h_file_content) |
| 166 file_fd.close() | 170 file_fd.close() |
| 167 file_fd = open(output_mm_path, 'w') | 171 file_fd = open(output_mm_path, 'w') |
| 168 file_fd.write(mm_file_content) | 172 file_fd.write(mm_file_content) |
| 169 file_fd.close() | 173 file_fd.close() |
| 170 | 174 |
| 171 return 0 | 175 return 0 |
| 172 | 176 |
| 173 if __name__ == '__main__': | 177 if __name__ == '__main__': |
| 174 sys.exit(Main(sys.argv)) | 178 sys.exit(Main(sys.argv)) |
| OLD | NEW |