diff options
author | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 13:32:21 +0000 |
---|---|---|
committer | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 13:32:21 +0000 |
commit | 92e1212fd2d33d4bf6489c51ae0d81e195ff3a5a (patch) | |
tree | 0a23a320e88bcc56175b164a5e0675f2702030a0 /build/mac | |
parent | 04bbad202d07b9c32f47aa9332ef95d3686e68ef (diff) | |
download | chromium_src-92e1212fd2d33d4bf6489c51ae0d81e195ff3a5a.zip chromium_src-92e1212fd2d33d4bf6489c51ae0d81e195ff3a5a.tar.gz chromium_src-92e1212fd2d33d4bf6489c51ae0d81e195ff3a5a.tar.bz2 |
ObjC classes generated by the build and used in Xib files is already getting ugly, if they aren't built at build start, IB sometimes throws warnings about unknown things, so...
- Use one class for the localizer and generate the table that drives it.
- Update the generator script to process a list of xib files and generate one header.
- Update the data within the GYP file to do this.
- This might actually help overall size since it helps force one set of strings for each different window.
- Switch to bsearch for table lookup since we have one, larger table now.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/164260
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23017 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/mac')
-rwxr-xr-x | build/mac/generate_localizer | 121 |
1 files changed, 38 insertions, 83 deletions
diff --git a/build/mac/generate_localizer b/build/mac/generate_localizer index c9d49f9..228751e 100755 --- a/build/mac/generate_localizer +++ b/build/mac/generate_localizer @@ -20,52 +20,22 @@ localizer_template_h = \ '''// ---------- WARNING ---------- // THIS IS A GENERATED FILE, DO NOT EDIT IT DIRECTLY! // -// Generated by %(generate_localizer)s. -// Generated from %(xib_file)s. +// This header includes the table used by ui_localizer.mm. Nothing else should +// be including this file. // - -#ifndef %(class_name)s_LOCALIZER_H_ -#define %(class_name)s_LOCALIZER_H_ - -#import "chrome/browser/cocoa/ui_localizer.h" - -// A subclass of ChromeUILocalizer that handles localization based on resource -// constants. - -@interface %(class_name)sLocalizer : ChromeUILocalizer -@end - -#endif // %(class_name)s_LOCALIZER_H_ -''' - -localizer_template_mm = \ -'''// ---------- WARNING ---------- -// THIS IS A GENERATED FILE, DO NOT EDIT IT DIRECTLY! -// -// Generated by '%(generate_localizer)s'. -// Generated from '%(xib_file)s'. +// Generated by %(generate_localizer)s. +// Generated from: +// %(xib_files)s // -#import "%(header_name)s" - -#include "grit/app_strings.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" +#ifndef UI_LOCALIZER_TABLE_H_ +#define UI_LOCALIZER_TABLE_H_ -@implementation %(class_name)sLocalizer - -- (NSString *)localizedStringForString:(NSString *)string { - - static const ui_localizer::ResourceMap kUIResources[] = { +static const UILocalizerResourceMap kUIResources[] = { %(resource_map_list)s }; - static const size_t kUIResourcesSize = arraysize(kUIResources); +static const size_t kUIResourcesSize = arraysize(kUIResources); - return ui_localizer::LocalizedStringForKeyFromMapList(string, - kUIResources, - kUIResourcesSize); -} - -@end +#endif // UI_LOCALIZER_TABLE_H_ ''' def xib_localizable_strings(xib_path): @@ -95,8 +65,8 @@ def extract_resource_constants(plist_localizable_strings_dict, xib_path): % (xib_path, generate_localizer, item_value)); return constants_list -def generate_files_contents(class_name, constants_list, header_name, xib_path): - """Generates a localizer files contents from the list of constants.""" +def generate_file_contents(constants_list, xib_paths): + """Generates the header listing the constants.""" # Bounce through a set to uniq the strings, sort the list, then build the # values we need from it. constants_list = sorted(set(constants_list)) @@ -112,15 +82,12 @@ def generate_files_contents(class_name, constants_list, header_name, xib_path): ( item, label_id[1:], label_arg_id) # Assemble the contents from the templates. values_dict = { - 'class_name': class_name, - 'header_name': header_name, 'resource_map_list': constant_list_str, 'generate_localizer': generate_localizer, - 'xib_file': xib_path, + 'xib_files': "\n// ".join(xib_paths), } h_file = localizer_template_h % values_dict - mm_file = localizer_template_mm % values_dict - return (h_file, mm_file) + return h_file def Main(argv=None): @@ -128,49 +95,37 @@ def Main(argv=None): generate_localizer = os.path.basename(argv[0]) # Args - if len(argv) != 4: - sys.stderr.write('%s:0: error: Expected xib and output file arguments\n' % + if len(argv) < 4: + sys.stderr.write('%s:0: error: Expected output file and then xibs\n' % generate_localizer); return 1 - xib_path, output_h_path, output_mm_path = argv[1:] - - # Run ibtool and convert to something Python can deal with - plist_string = xib_localizable_strings(xib_path) - if not plist_string: - return 2 - plist = plistlib.readPlistFromString(plist_string) - - # Extract the resource constant strings - localizable_strings = plist['com.apple.ibtool.document.localizable-strings'] - constants_list = extract_resource_constants(localizable_strings, xib_path) - if not constants_list: - sys.stderr.write("%s:0: warning: %s didn't find any resource strings\n" % - (xib_path, generate_localizer)); - # Seed constant_list with an entry so things will compile even though the - # array sould really be empty (array_size in the generated file doesn't - # like an empty array). - constants_list.append('^0'); - - # Name the class based on the output file - class_name = os.path.splitext(os.path.basename(output_h_path))[0] - suffix = '_localizer' - if class_name.endswith(suffix): - class_name = class_name[:-len(suffix)]; - class_name = class_name.replace('_', ' ').title().replace(' ', ''); + output_path = argv[1]; + xib_paths = argv[2:] + + full_constants_list = [] + for xib_path in xib_paths: + # Run ibtool and convert to something Python can deal with + plist_string = xib_localizable_strings(xib_path) + if not plist_string: + return 2 + plist = plistlib.readPlistFromString(plist_string) + + # Extract the resource constant strings + localizable_strings = plist['com.apple.ibtool.document.localizable-strings'] + constants_list = extract_resource_constants(localizable_strings, xib_path) + if not constants_list: + sys.stderr.write("%s:0: warning: %s didn't find any resource strings\n" % + (xib_path, generate_localizer)); + full_constants_list.extend(constants_list) # Generate our file contents - (h_file_content, mm_file_content) = \ - generate_files_contents(class_name, constants_list, - os.path.basename(output_h_path), - xib_path) + h_file_content = \ + generate_file_contents(full_constants_list, xib_paths) - # Write out the files - file_fd = open(output_h_path, 'w') + # Write out the file + file_fd = open(output_path, 'w') file_fd.write(h_file_content) file_fd.close() - file_fd = open(output_mm_path, 'w') - file_fd.write(mm_file_content) - file_fd.close() return 0 |