aboutsummaryrefslogtreecommitdiff
path: root/iPhone
diff options
context:
space:
mode:
authorGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2011-11-16 14:30:21 +0000
committerGravatar gtm.daemon <gtm.daemon@7dc7ac4e-7543-0410-b95c-c1676fc8e2a3>2011-11-16 14:30:21 +0000
commit711247f40bf28cc93e8be3e74bc5d654884c9ce4 (patch)
treebc5bc9f7fa4f47b49bd547a031535da7c6f8074e /iPhone
parent73d9542bde42d7b172f5db221d3403ceb4bdcf51 (diff)
[Author: qsr]
Handle UIButton in GTMUILocalizer To be noted: UISegmented Controls and UISearchBars were alredy working. UISwitch doesn't have any strings to be localized. R=dmaclach,thomasvl APPROVED=thomasvl
Diffstat (limited to 'iPhone')
-rw-r--r--iPhone/GTMUILocalizer.h5
-rw-r--r--iPhone/GTMUILocalizer.m23
-rw-r--r--iPhone/GTMUILocalizerTest.h6
-rw-r--r--iPhone/GTMUILocalizerTest.m72
-rw-r--r--iPhone/GTMUILocalizerTest.xib229
5 files changed, 296 insertions, 39 deletions
diff --git a/iPhone/GTMUILocalizer.h b/iPhone/GTMUILocalizer.h
index d34c4d0..7493c89 100644
--- a/iPhone/GTMUILocalizer.h
+++ b/iPhone/GTMUILocalizer.h
@@ -31,11 +31,6 @@
// be looked up in the Localizable.strings table without the caret as the
// key.
//
-// TODO(tvl): this correct for iOS?
-// Due to technical limitations, accessibility description cannot be localized.
-// See http://lists.apple.com/archives/Accessibility-dev/2009/Dec/msg00004.html
-// and http://openradar.appspot.com/7496255 for more information.
-//
// As an example if I wanted to localize a button with the word "Print" on
// it, I would put it in a view controlled by a UIViewController that was
// the owner of the nib. I would set it's title to be "^Print". I would then
diff --git a/iPhone/GTMUILocalizer.m b/iPhone/GTMUILocalizer.m
index efebc42..c6b7fca 100644
--- a/iPhone/GTMUILocalizer.m
+++ b/iPhone/GTMUILocalizer.m
@@ -26,7 +26,7 @@
// -[self localizeObject:recursively:].
- (void)localizeToolbar:(UIToolbar *)toolbar;
- (void)localizeView:(UIView *)view recursively:(BOOL)recursive;
-
+- (void)localizeButton:(UIButton *)button;
@end
@implementation GTMUILocalizer
@@ -130,6 +130,11 @@
}
}
+ // Specific types
+ if ([view isKindOfClass:[UIButton class]]) {
+ [self localizeButton:(UIButton *)view];
+ }
+
// Then do all possible strings.
if ([view respondsToSelector:@selector(title)]
&& [view respondsToSelector:@selector(setTitle:)]) {
@@ -212,4 +217,20 @@
}
}
+- (void)localizeButton:(UIButton *)button {
+ UIControlState allStates[] = { UIControlStateNormal,
+ UIControlStateHighlighted,
+ UIControlStateDisabled,
+ UIControlStateSelected };
+ for (size_t idx = 0; idx < (sizeof(allStates)/sizeof(allStates[0])) ; ++idx) {
+ UIControlState state = allStates[idx];
+ NSString *value = [button titleForState:state];
+ if (value) {
+ NSString* localizedValue = [self localizedStringForString:value];
+ if (localizedValue)
+ [button setTitle:localizedValue forState:state];
+ }
+ }
+}
+
@end
diff --git a/iPhone/GTMUILocalizerTest.h b/iPhone/GTMUILocalizerTest.h
index 87a0f22..0ee846c 100644
--- a/iPhone/GTMUILocalizerTest.h
+++ b/iPhone/GTMUILocalizerTest.h
@@ -22,8 +22,14 @@
@interface GTMUILocalizerTestViewController : UIViewController {
@private
UILabel *label_;
+ UIButton *button_;
+ UISegmentedControl *segmentedControl_;
+ UISearchBar *searchBar_;
}
@property(nonatomic, retain) IBOutlet UILabel *label;
+@property(nonatomic, retain) IBOutlet UIButton *button;
+@property(nonatomic, retain) IBOutlet UISegmentedControl *segmentedControl;
+@property(nonatomic, retain) IBOutlet UISearchBar *searchBar;
@end
diff --git a/iPhone/GTMUILocalizerTest.m b/iPhone/GTMUILocalizerTest.m
index 682285d..dfe1f32 100644
--- a/iPhone/GTMUILocalizerTest.m
+++ b/iPhone/GTMUILocalizerTest.m
@@ -24,7 +24,10 @@
@implementation TestUILocalizer
- (NSString *)localizedStringForString:(NSString *)string {
- return [string substringFromIndex:5];
+ if ([string length] >= 5)
+ return [string substringFromIndex:5];
+ else
+ return string;
}
- (void)localize:(id)object {
@@ -36,6 +39,9 @@
@implementation GTMUILocalizerTestViewController
@synthesize label = label_;
+@synthesize button = button_;
+@synthesize segmentedControl = segmentedControl_;
+@synthesize searchBar = searchBar_;
- (id)init {
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
@@ -44,44 +50,64 @@
@end
@interface GTMUILocalizerTest : GTMTestCase
+- (void)checkValues:(NSString *)value
+ onController:(GTMUILocalizerTestViewController *)controller;
@end
@implementation GTMUILocalizerTest
-- (void)testLocalization {
- GTMUILocalizerTestViewController* controller =
- [[GTMUILocalizerTestViewController alloc] init];
-
- // Load the view.
- [controller view];
-
- STAssertEqualStrings(@"^IDS_FOO", [[controller label] text], nil);
+- (void)checkValues:(NSString *)value
+ onController:(GTMUILocalizerTestViewController *)controller {
+ // Label
+ STAssertEqualStrings(value, [[controller label] text], nil);
+ // Button
+ UIControlState allStates[] = { UIControlStateNormal,
+ UIControlStateHighlighted,
+ UIControlStateDisabled,
+ UIControlStateSelected };
+ for (size_t idx = 0; idx < (sizeof(allStates)/sizeof(allStates[0])) ; ++idx) {
+ UIControlState state = allStates[idx];
+ STAssertEqualStrings(value, [[controller button] titleForState:state], nil);
+ }
+ // SegementedControl
+ for (NSUInteger i = 0;
+ i < [[controller segmentedControl] numberOfSegments];
+ ++i) {
+ STAssertEqualStrings(value,
+ [[controller segmentedControl] titleForSegmentAtIndex:i], nil);
+ }
+ // SearchBar
+ STAssertEqualStrings(value, [[controller searchBar] text], nil);
+ STAssertEqualStrings(value, [[controller searchBar] placeholder], nil);
+ STAssertEqualStrings(value, [[controller searchBar] prompt], nil);
// Accessibility label seems to not be working at all. They always are nil.
-// Even when setting those explicitely there, the getter always returns nil.
+// Even when setting those explicitly there, the getter always returns nil.
// This might cause because the gobal accessibility switch is not on during the
// tests.
#if 0
- STAssertEqualStrings(@"^IDS_FOO", [[controller view] accessibilityLabel],
+ STAssertEqualStrings(value, [[controller view] accessibilityLabel],
nil);
- STAssertEqualStrings(@"^IDS_FOO", [[controller view] accessibilityHint],
+ STAssertEqualStrings(value, [[controller view] accessibilityHint],
nil);
- STAssertEqualStrings(@"^IDS_FOO", [[controller label] accessibilityLabel],
+ STAssertEqualStrings(value, [[controller label] accessibilityLabel],
nil);
- STAssertEqualStrings(@"^IDS_FOO", [[controller label] accessibilityHint],
+ STAssertEqualStrings(value, [[controller label] accessibilityHint],
nil);
#endif
+}
+
+- (void)testLocalization {
+ GTMUILocalizerTestViewController *controller =
+ [[GTMUILocalizerTestViewController alloc] init];
+
+ // Load the view.
+ [controller view];
+
+ [self checkValues:@"^IDS_FOO" onController:controller];
TestUILocalizer *localizer = [[TestUILocalizer alloc] init];
[localizer localize:[controller view]];
- STAssertEqualStrings(@"FOO", [[controller label] text], nil);
-
-// Accessibility label seems to not be working at all. They always are nil.
-#if 0
- STAssertEqualStrings(@"FOO", [[controller view] accessibilityLabel], nil);
- STAssertEqualStrings(@"FOO", [[controller view] accessibilityHint], nil);
- STAssertEqualStrings(@"FOO", [[controller label] accessibilityLabel], nil);
- STAssertEqualStrings(@"FOO", [[controller label] accessibilityHint], nil);
-#endif
+ [self checkValues:@"FOO" onController:controller];
}
@end
diff --git a/iPhone/GTMUILocalizerTest.xib b/iPhone/GTMUILocalizerTest.xib
index ed6a8a4..2f4379f 100644
--- a/iPhone/GTMUILocalizerTest.xib
+++ b/iPhone/GTMUILocalizerTest.xib
@@ -45,7 +45,7 @@
<object class="IBUILabel" id="505819666">
<reference key="NSNextResponder" ref="971589104"/>
<int key="NSvFlags">292</int>
- <string key="NSFrame">{{115, 182}, {136, 21}}</string>
+ <string key="NSFrame">{{98, 132}, {136, 21}}</string>
<reference key="NSSuperview" ref="971589104"/>
<bool key="IBUIOpaque">NO</bool>
<bool key="IBUIClipsSubviews">YES</bool>
@@ -62,13 +62,91 @@
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MCAwIDAAA</bytes>
</object>
- <object class="NSColor" key="IBUIHighlightedColor">
+ <object class="NSColor" key="IBUIHighlightedColor" id="321460951">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
<int key="IBUIBaselineAdjustment">1</int>
<float key="IBUIMinimumFontSize">10</float>
</object>
+ <object class="IBUIButton" id="264984021">
+ <reference key="NSNextResponder" ref="971589104"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{81, 73}, {143, 37}}</string>
+ <reference key="NSSuperview" ref="971589104"/>
+ <bool key="IBUIOpaque">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <int key="IBUIContentHorizontalAlignment">0</int>
+ <int key="IBUIContentVerticalAlignment">0</int>
+ <object class="NSFont" key="IBUIFont">
+ <string key="NSName">Helvetica-Bold</string>
+ <double key="NSSize">15</double>
+ <int key="NSfFlags">16</int>
+ </object>
+ <int key="IBUIButtonType">1</int>
+ <string key="IBUIHighlightedTitle">^IDS_FOO</string>
+ <string key="IBUIDisabledTitle">^IDS_FOO</string>
+ <string key="IBUISelectedTitle">^IDS_FOO</string>
+ <string key="IBUINormalTitle">^IDS_FOO</string>
+ <reference key="IBUIHighlightedTitleColor" ref="321460951"/>
+ <object class="NSColor" key="IBUINormalTitleColor">
+ <int key="NSColorSpace">1</int>
+ <bytes key="NSRGB">MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA</bytes>
+ </object>
+ <object class="NSColor" key="IBUINormalTitleShadowColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC41AA</bytes>
+ </object>
+ </object>
+ <object class="IBUISegmentedControl" id="841426246">
+ <reference key="NSNextResponder" ref="971589104"/>
+ <int key="NSvFlags">292</int>
+ <string key="NSFrame">{{44, 289}, {207, 44}}</string>
+ <reference key="NSSuperview" ref="971589104"/>
+ <bool key="IBUIOpaque">NO</bool>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <int key="IBNumberOfSegments">2</int>
+ <int key="IBSelectedSegmentIndex">0</int>
+ <object class="NSArray" key="IBSegmentTitles">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>^IDS_FOO</string>
+ <string>^IDS_FOO</string>
+ </object>
+ <object class="NSMutableArray" key="IBSegmentWidths">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <real value="0.0"/>
+ <real value="0.0"/>
+ </object>
+ <object class="NSMutableArray" key="IBSegmentEnabledStates">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <boolean value="YES"/>
+ <boolean value="YES"/>
+ </object>
+ <object class="NSMutableArray" key="IBSegmentContentOffsets">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>{0, 0}</string>
+ <string>{0, 0}</string>
+ </object>
+ <object class="NSMutableArray" key="IBSegmentImages">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSNull" id="4"/>
+ <reference ref="4"/>
+ </object>
+ </object>
+ <object class="IBUISearchBar" id="365108886">
+ <reference key="NSNextResponder" ref="971589104"/>
+ <int key="NSvFlags">290</int>
+ <string key="NSFrame">{{0, 199}, {320, 75}}</string>
+ <reference key="NSSuperview" ref="971589104"/>
+ <int key="IBUIContentMode">3</int>
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ <string key="IBText">^IDS_FOO</string>
+ <string key="IBPrompt">^IDS_FOO</string>
+ <string key="IBPlaceholder">^IDS_FOO</string>
+ <object class="IBUITextInputTraits" key="IBTextInputTraits">
+ <string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
+ </object>
+ </object>
</object>
<string key="NSFrameSize">{320, 460}</string>
<reference key="NSSuperview"/>
@@ -106,6 +184,38 @@
</object>
<int key="connectionID">13</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">delegate</string>
+ <reference key="source" ref="365108886"/>
+ <reference key="destination" ref="841351856"/>
+ </object>
+ <int key="connectionID">26</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">button</string>
+ <reference key="source" ref="841351856"/>
+ <reference key="destination" ref="264984021"/>
+ </object>
+ <int key="connectionID">28</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">segmentedControl</string>
+ <reference key="source" ref="841351856"/>
+ <reference key="destination" ref="841426246"/>
+ </object>
+ <int key="connectionID">29</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBCocoaTouchOutletConnection" key="connection">
+ <string key="label">searchBar</string>
+ <reference key="source" ref="841351856"/>
+ <reference key="destination" ref="365108886"/>
+ </object>
+ <int key="connectionID">30</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -132,7 +242,10 @@
<reference key="object" ref="971589104"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="264984021"/>
+ <reference ref="841426246"/>
<reference ref="505819666"/>
+ <reference ref="365108886"/>
</object>
<reference key="parent" ref="0"/>
</object>
@@ -141,6 +254,21 @@
<reference key="object" ref="505819666"/>
<reference key="parent" ref="971589104"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">16</int>
+ <reference key="object" ref="264984021"/>
+ <reference key="parent" ref="971589104"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">17</int>
+ <reference key="object" ref="841426246"/>
+ <reference key="parent" ref="971589104"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">18</int>
+ <reference key="object" ref="365108886"/>
+ <reference key="parent" ref="971589104"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -149,21 +277,35 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>-1.CustomClassName</string>
<string>-2.CustomClassName</string>
+ <string>16.IBPluginDependency</string>
+ <string>17.IBPluginDependency</string>
+ <string>18.IBPluginDependency</string>
+ <string>18.IBViewBoundsToFrameTransform</string>
<string>5.IBEditorWindowLastContentRect</string>
<string>5.IBPluginDependency</string>
<string>5.IBViewBoundsToFrameTransform</string>
<string>9.IBPluginDependency</string>
+ <string>9.IBViewBoundsToFrameTransform</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>GTMUILocalizerTestViewController</string>
<string>UIResponder</string>
- <string>{{870, 485}, {320, 460}}</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <object class="NSAffineTransform">
+ <bytes key="NSTransformStruct">P4AAAL+AAABBUAAAw4cAAA</bytes>
+ </object>
+ <string>{{299, 515}, {320, 460}}</string>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
<object class="NSAffineTransform">
<bytes key="NSTransformStruct">P4AAAL+AAAAAAAAAw+UAAA</bytes>
</object>
<string>com.apple.InterfaceBuilder.IBCocoaTouchPlugin</string>
+ <object class="NSAffineTransform">
+ <bytes key="NSTransformStruct">P4AAAL+AAABC5gAAw0kAAA</bytes>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -182,7 +324,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">15</int>
+ <int key="maxID">30</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -191,14 +333,49 @@
<string key="className">GTMUILocalizerTestViewController</string>
<string key="superclassName">UIViewController</string>
<object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">label</string>
- <string key="NS.object.0">UILabel</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>button</string>
+ <string>label</string>
+ <string>searchBar</string>
+ <string>segmentedControl</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>UIButton</string>
+ <string>UILabel</string>
+ <string>UISearchBar</string>
+ <string>UISegmentedControl</string>
+ </object>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
- <string key="NS.key.0">label</string>
- <object class="IBToOneOutletInfo" key="NS.object.0">
- <string key="name">label</string>
- <string key="candidateClassName">UILabel</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>button</string>
+ <string>label</string>
+ <string>searchBar</string>
+ <string>segmentedControl</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBToOneOutletInfo">
+ <string key="name">button</string>
+ <string key="candidateClassName">UIButton</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">label</string>
+ <string key="candidateClassName">UILabel</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">searchBar</string>
+ <string key="candidateClassName">UISearchBar</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">segmentedControl</string>
+ <string key="candidateClassName">UISegmentedControl</string>
+ </object>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
@@ -207,6 +384,14 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">GTMUILocalizerTestViewController</string>
+ <string key="superclassName">UIViewController</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBUserSource</string>
+ <string key="minorKey"/>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
@@ -361,6 +546,22 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">UIButton</string>
+ <string key="superclassName">UIControl</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIButton.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">UIControl</string>
+ <string key="superclassName">UIView</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UIControl.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">UILabel</string>
<string key="superclassName">UIView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
@@ -390,6 +591,14 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">UISegmentedControl</string>
+ <string key="superclassName">UIControl</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBFrameworkSource</string>
+ <string key="minorKey">UIKit.framework/Headers/UISegmentedControl.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">UIView</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBFrameworkSource</string>