diff options
author | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2011-11-02 18:30:18 +0000 |
---|---|---|
committer | gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3> | 2011-11-02 18:30:18 +0000 |
commit | 1204639d4aeeac3d3dda7b0c53b8941266b9e685 (patch) | |
tree | 37db0dee0bdaad00e3c6faf9c50d2c3804b598b6 /AppKit/GTMUILocalizer.m | |
parent | fe8209a1d04223c70727a4e87cfe53d5bd4192c0 (diff) |
[Author: thomasvl]
- Support for localizing non datasource versions of NSComboxBox (http://code.google.com/p/google-toolbox-for-mac/issues/detail?id=77).
- Fix up some category names.
- Avoid conflicting category names.
- Move placeholder string support down to NSTextField instead of NSSearchField.
- Support for NSTextField placeholder in unittesting state.
- Support for non datasource combobox values in unittesting state.
- Fix NSSegmentControl localization support.
- Add explicit tests for no localized values and document it in the strings file.
- Unittesting for as much as possible of the above.
R=dmaclach
DELTA=762 (660 added, 55 deleted, 47 changed)
Diffstat (limited to 'AppKit/GTMUILocalizer.m')
-rw-r--r-- | AppKit/GTMUILocalizer.m | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/AppKit/GTMUILocalizer.m b/AppKit/GTMUILocalizer.m index 56b0b7d..ffcc11d 100644 --- a/AppKit/GTMUILocalizer.m +++ b/AppKit/GTMUILocalizer.m @@ -23,7 +23,7 @@ - (void)localizeAccessibility:(id)object; - (void)localizeBindings:(id)object; -// Never recursively call any of these methods. Always call +// Never recursively call any of these methods. Always call // -[self localizeObject:recursively:] otherwise bindings will not be // localized properly. - (void)localizeWindow:(NSWindow *)window recursively:(BOOL)recursive; @@ -240,12 +240,12 @@ } } - // Do NSSearchField placeholders - if ([view isKindOfClass:[NSSearchField class]]) { - NSString *placeholder = [[(NSSearchField *)view cell] placeholderString]; + // Do NSTextField placeholders + if ([view isKindOfClass:[NSTextField class]]) { + NSString *placeholder = [[(NSTextField *)view cell] placeholderString]; NSString *localizedPlaceholer = [self localizedStringForString:placeholder]; if (localizedPlaceholer) { - [[(NSSearchField *)view cell] setPlaceholderString:localizedPlaceholer]; + [[(NSTextField *)view cell] setPlaceholderString:localizedPlaceholer]; } } @@ -282,8 +282,37 @@ NSSegmentedControl *segmentedControl = (NSSegmentedControl *)view; for (NSInteger i = 0; i < [segmentedControl segmentCount]; ++i) { NSString *label = [segmentedControl labelForSegment:i]; - [segmentedControl setLabel:[self localizedStringForString:label] - forSegment:i]; + NSString *localizedLabel = [self localizedStringForString:label]; + if (localizedLabel) { + [segmentedControl setLabel:localizedLabel forSegment:i]; + } + } + } + + // Do NSComboBox items. + if ([view isKindOfClass:[NSComboBox class]]) { + NSComboBox *combobox = (NSComboBox*)view; + // Make sure it doesn't use a DataSource. + if (![combobox usesDataSource]) { + NSMutableArray *localizedValues = [NSMutableArray array]; + BOOL replaceValues = NO; + NSString *value; + GTM_FOREACH_OBJECT(value, [combobox objectValues]) { + NSString *localizedValue = nil; + if ([value isKindOfClass:[NSString class]]) { + localizedValue = [self localizedStringForString:value]; + } + if (localizedValue) { + replaceValues = YES; + [localizedValues addObject:localizedValue]; + } else { + [localizedValues addObject:value]; + } + } + if (replaceValues) { + [combobox removeAllItems]; + [combobox addItemsWithObjectValues:localizedValues]; + } } } } @@ -343,10 +372,10 @@ NSString *path = [bindingInfo objectForKey:NSObservedKeyPathKey]; NSDictionary *options = [bindingInfo objectForKey:NSOptionsKey]; if (observedObject && path && options) { - NSMutableDictionary *newOptions + NSMutableDictionary *newOptions = [NSMutableDictionary dictionaryWithDictionary:options]; BOOL valueChanged = NO; - for (size_t i = 0; + for (size_t i = 0; i < sizeof(optionsToLocalize) / sizeof(optionsToLocalize[0]); ++i) { NSString *key = optionsToLocalize[i]; @@ -362,9 +391,9 @@ if (valueChanged) { // Only unbind and rebind if there is a change. [object unbind:exposedBinding]; - [object bind:exposedBinding - toObject:observedObject - withKeyPath:path + [object bind:exposedBinding + toObject:observedObject + withKeyPath:path options:newOptions]; } } |