From 1204639d4aeeac3d3dda7b0c53b8941266b9e685 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Wed, 2 Nov 2011 18:30:18 +0000 Subject: [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) --- AppKit/GTMUILocalizer.m | 53 ++++- AppKit/GTMUILocalizerTestWindow.xib | 258 +++++++++++++++++++-- AppKit/GTMUILocalizerTestWindow_10_4.xib | 246 ++++++++++++++++++-- .../GTMUILocalizerWindow3State.10_4_SDK.gtmUTState | 40 ++++ .../TestData/GTMUILocalizerWindow3State.gtmUTState | 42 +++- .../Resources/English.lproj/Localizable.strings | 8 +- 6 files changed, 593 insertions(+), 54 deletions(-) (limited to 'AppKit') 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]; } } diff --git a/AppKit/GTMUILocalizerTestWindow.xib b/AppKit/GTMUILocalizerTestWindow.xib index 6161945..8bb4172 100644 --- a/AppKit/GTMUILocalizerTestWindow.xib +++ b/AppKit/GTMUILocalizerTestWindow.xib @@ -2,18 +2,18 @@ 1050 - 10D2063a - 762 - 1038.29 - 460.00 + 10K549 + 851 + 1038.36 + 461.00 com.apple.InterfaceBuilder.CocoaPlugin - 762 + 851 YES + - @@ -196,7 +196,7 @@ 6 System controlColor - + 3 MC42NjY2NjY2NjY3AA @@ -1204,6 +1204,107 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 1 + + + 268 + {{371, 180}, {92, 26}} + + YES + + 343014976 + 272630784 + ^Label1 + + ^Placeholder1 + + YES + + + 4 + YES + + YES + ^Choice1 + ^Choice2 + ^Choice3 + ^Choice4 + ^Choice5 + + + + + 274 + {13, 105} + + + YES + + YES + + + 10 + 10 + 1000 + + 75628032 + 0 + + + LucidaGrande + 12 + 16 + + + 3 + MC4zMzMzMzI5ODU2AA + + + + + 338820672 + 1024 + + + YES + + 6 + System + controlBackgroundColor + + + + + 3 + YES + + + + 3 + 2 + + + 6 + System + gridColor + + 3 + MC41AA + + + 19 + tableViewAction: + -765427712 + + + + 1 + 15 + 0 + YES + 0 + + + {480, 270} @@ -1631,6 +1732,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA + @@ -1873,6 +1975,20 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA + + 173 + + + YES + + + + + + 174 + + + @@ -1900,6 +2016,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 16.IBPluginDependency 169.IBPluginDependency 170.IBPluginDependency + 173.IBPluginDependency + 173.IBViewBoundsToFrameTransform + 174.IBPluginDependency 2.IBPluginDependency 22.IBEditorWindowLastContentRect 22.IBPluginDependency @@ -1962,9 +2081,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{329, 451}, {480, 270}} + {{387, 451}, {480, 270}} com.apple.InterfaceBuilder.CocoaPlugin - {{329, 451}, {480, 270}} + {{387, 451}, {480, 270}} {196, 240} {{357, 418}, {480, 270}} @@ -1981,9 +2100,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{960, 479}, {480, 270}} + + P4AAAL+AAABDuYAAw0wAAA + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{948, 629}, {480, 270}} com.apple.InterfaceBuilder.CocoaPlugin - {{960, 479}, {480, 270}} + {{948, 629}, {480, 270}} com.apple.InterfaceBuilder.CocoaPlugin {{126, 673}, {161, 23}} @@ -2054,7 +2178,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - 170 + 174 @@ -2077,6 +2201,30 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA id + + YES + + YES + otherObjectToLocalize_ + owner_ + yetAnotherObjectToLocalize_ + + + YES + + otherObjectToLocalize_ + id + + + owner_ + id + + + yetAnotherObjectToLocalize_ + id + + + IBProjectSource AppKit/GTMUILocalizer.h @@ -2104,6 +2252,40 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA NSWindow + + YES + + YES + anotherWindow_ + bindingsSearchField_ + bindingsTextField_ + otherMenu_ + otherWindow_ + + + YES + + anotherWindow_ + NSWindow + + + bindingsSearchField_ + NSSearchField + + + bindingsTextField_ + NSTextField + + + otherMenu_ + NSMenu + + + otherWindow_ + NSWindow + + + IBProjectSource AppKit/GTMUILocalizerTest.h @@ -2123,6 +2305,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA UnitTesting/GTMAppKitUnitTestingUtilities.h + + NSBox + + NSButton @@ -2131,6 +2317,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA NSCell + + NSComboBox + + NSControl @@ -2161,13 +2351,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA AppKit/GTMDelegatingTableColumn.h - - NSObject - - IBProjectSource - Foundation/GTMHTTPServer.h - - NSObject @@ -2203,6 +2386,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA UnitTesting/GTMNSObject+UnitTesting.h + + NSSegmentedControl + + NSTabView @@ -2215,6 +2402,14 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA NSTextField + + NSToolbar + + + + NSToolbarItem + + NSView @@ -2320,6 +2515,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA AppKit.framework/Headers/NSCell.h + + NSComboBox + NSTextField + + IBFrameworkSource + AppKit.framework/Headers/NSComboBox.h + + + + NSComboBoxCell + NSTextFieldCell + + IBFrameworkSource + AppKit.framework/Headers/NSComboBoxCell.h + + NSControl NSView @@ -2847,6 +3058,13 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA showWindow: id + + showWindow: + + showWindow: + id + + IBFrameworkSource AppKit.framework/Headers/NSWindowController.h @@ -2862,7 +3080,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin.macosx - + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 diff --git a/AppKit/GTMUILocalizerTestWindow_10_4.xib b/AppKit/GTMUILocalizerTestWindow_10_4.xib index 93cb909..6316e33 100644 --- a/AppKit/GTMUILocalizerTestWindow_10_4.xib +++ b/AppKit/GTMUILocalizerTestWindow_10_4.xib @@ -2,18 +2,18 @@ 1040 - 10D2063a - 762 - 1038.29 - 460.00 + 10K549 + 851 + 1038.36 + 461.00 com.apple.InterfaceBuilder.CocoaPlugin - 762 + 851 YES - + @@ -117,7 +117,7 @@ 6 System controlColor - + 3 MC42NjY2NjY2NjY3AA @@ -1089,6 +1089,107 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA {{42, 66}, {106, 45}} + + + 268 + {{371, 180}, {92, 26}} + + YES + + 343014976 + 272630784 + ^Label1 + + ^Placeholder1 + + YES + + + 4 + YES + + YES + ^Choice1 + ^Choice2 + ^Choice3 + ^Choice4 + ^Choice5 + + + + + 274 + {13, 105} + + + YES + + YES + + + 10 + 10 + 1000 + + 75628032 + 0 + + + LucidaGrande + 12 + 16 + + + 3 + MC4zMzMzMzI5ODU2AA + + + + + 338820672 + 1024 + + + YES + + 6 + System + controlBackgroundColor + + + + + 3 + YES + + + + 3 + 2 + + + 6 + System + gridColor + + 3 + MC41AA + + + 19 + tableViewAction: + -765427712 + + + + 1 + 15 + 0 + YES + 0 + + + {480, 270} @@ -1549,6 +1650,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA + @@ -1757,6 +1859,20 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA + + 120 + + + YES + + + + + + 121 + + + @@ -1777,6 +1893,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA 101.IBPluginDependency 11.IBPluginDependency 12.IBPluginDependency + 120.IBPluginDependency + 120.IBViewBoundsToFrameTransform + 121.IBPluginDependency 13.IBPluginDependency 14.IBPluginDependency 15.IBPluginDependency @@ -1840,9 +1959,9 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{174, 487}, {480, 270}} + {{174, 328}, {480, 270}} com.apple.InterfaceBuilder.CocoaPlugin - {{174, 487}, {480, 270}} + {{174, 328}, {480, 270}} {196, 240} {{357, 418}, {480, 270}} @@ -1852,13 +1971,18 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABDuYAAw0wAAA + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{324, 479}, {480, 270}} com.apple.InterfaceBuilder.CocoaPlugin - {{324, 479}, {480, 270}} + com.apple.InterfaceBuilder.CocoaPlugin + {{387, 479}, {480, 270}} + com.apple.InterfaceBuilder.CocoaPlugin + {{387, 479}, {480, 270}} com.apple.InterfaceBuilder.CocoaPlugin {{126, 673}, {161, 23}} @@ -1926,7 +2050,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA - 119 + 121 @@ -1949,6 +2073,30 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA id + + YES + + YES + otherObjectToLocalize_ + owner_ + yetAnotherObjectToLocalize_ + + + YES + + otherObjectToLocalize_ + id + + + owner_ + id + + + yetAnotherObjectToLocalize_ + id + + + IBProjectSource AppKit/GTMUILocalizer.h @@ -1976,6 +2124,40 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA NSWindow + + YES + + YES + anotherWindow_ + bindingsSearchField_ + bindingsTextField_ + otherMenu_ + otherWindow_ + + + YES + + anotherWindow_ + NSWindow + + + bindingsSearchField_ + NSSearchField + + + bindingsTextField_ + NSTextField + + + otherMenu_ + NSMenu + + + otherWindow_ + NSWindow + + + IBProjectSource AppKit/GTMUILocalizerTest.h @@ -1995,6 +2177,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA UnitTesting/GTMAppKitUnitTestingUtilities.h + + NSBox + + NSButton @@ -2003,6 +2189,10 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA NSCell + + NSComboBox + + NSControl @@ -2033,13 +2223,6 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA AppKit/GTMDelegatingTableColumn.h - - NSObject - - IBProjectSource - Foundation/GTMHTTPServer.h - - NSObject @@ -2192,6 +2375,22 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA AppKit.framework/Headers/NSCell.h + + NSComboBox + NSTextField + + IBFrameworkSource + AppKit.framework/Headers/NSComboBox.h + + + + NSComboBoxCell + NSTextFieldCell + + IBFrameworkSource + AppKit.framework/Headers/NSComboBoxCell.h + + NSControl NSView @@ -2690,6 +2889,13 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA showWindow: id + + showWindow: + + showWindow: + id + + IBFrameworkSource AppKit.framework/Headers/NSWindowController.h @@ -2705,7 +2911,7 @@ AAMAAAABAAEAAAFTAAMAAAAEAAAFwgAAAAAACAAIAAgACAABAAEAAQABA com.apple.InterfaceBuilder.CocoaPlugin.macosx - + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 diff --git a/AppKit/TestData/GTMUILocalizerWindow3State.10_4_SDK.gtmUTState b/AppKit/TestData/GTMUILocalizerWindow3State.10_4_SDK.gtmUTState index ed88b68..ea1d10c 100644 --- a/AppKit/TestData/GTMUILocalizerWindow3State.10_4_SDK.gtmUTState +++ b/AppKit/TestData/GTMUILocalizerWindow3State.10_4_SDK.gtmUTState @@ -293,6 +293,46 @@ + ViewSubView 3 + + ComboBoxNumberOfItems + 5 + ComboBoxNumberOfVisibleItems + 4 + ComboBoxObjectValue 0 + Localized Choice 1 + ComboBoxObjectValue 1 + Localized Choice 2 + ComboBoxObjectValue 2 + Localized Choice 3 + ComboBoxObjectValue 3 + ^Choice4 + ComboBoxObjectValue 4 + ^Choice5 + ControlIsEnabled + + ControlSelectedCell + + CellState + 0 + CellTag + 0 + CellTitle + Localized Label + CellValue + Localized Label + + ControlTag + 0 + ControlType + NSComboBox + ControlValue + Localized Label + PlaceHolderString + Localized Placeholder + ViewIsHidden + + WindowIsMain diff --git a/AppKit/TestData/GTMUILocalizerWindow3State.gtmUTState b/AppKit/TestData/GTMUILocalizerWindow3State.gtmUTState index 8352b5e..6958e6e 100644 --- a/AppKit/TestData/GTMUILocalizerWindow3State.gtmUTState +++ b/AppKit/TestData/GTMUILocalizerWindow3State.gtmUTState @@ -319,12 +319,52 @@ Segment 1 Localized Segment 2 Segment 2 - Localized Segment 3 + ^Seg3 SegmentCount 3 ViewIsHidden + ViewSubView 4 + + ComboBoxNumberOfItems + 5 + ComboBoxNumberOfVisibleItems + 4 + ComboBoxObjectValue 0 + Localized Choice 1 + ComboBoxObjectValue 1 + Localized Choice 2 + ComboBoxObjectValue 2 + Localized Choice 3 + ComboBoxObjectValue 3 + ^Choice4 + ComboBoxObjectValue 4 + ^Choice5 + ControlIsEnabled + + ControlSelectedCell + + CellState + 0 + CellTag + 0 + CellTitle + Localized Label + CellValue + Localized Label + + ControlTag + 0 + ControlType + NSComboBox + ControlValue + Localized Label + PlaceHolderString + Localized Placeholder + ViewIsHidden + + WindowIsMain diff --git a/AppKit/TestData/Resources/English.lproj/Localizable.strings b/AppKit/TestData/Resources/English.lproj/Localizable.strings index e6452a8..b45dc87 100644 --- a/AppKit/TestData/Resources/English.lproj/Localizable.strings +++ b/AppKit/TestData/Resources/English.lproj/Localizable.strings @@ -16,6 +16,9 @@ // the License. // +// NOTE: Some things in the UI aren't here to confirm that they get left +// along instead of replaced with an empty string. + // GTMUILocalizerTest strings "Button1" = "Localized Button"; "Label1" = "Localized Label"; @@ -39,7 +42,10 @@ "Box" = "Localized Box"; "Seg1" = "Localized Segment 1"; "Seg2" = "Localized Segment 2"; -"Seg3" = "Localized Segment 3"; +"Choice1" = "Localized Choice 1"; +"Choice2" = "Localized Choice 2"; +"Choice3" = "Localized Choice 3"; +"Placeholder1" = "Localized Placeholder"; // Binding localization strings. "MultipleValuesPlaceholder" = "MultipleValuesPlaceholder"; -- cgit v1.2.3