From 711247f40bf28cc93e8be3e74bc5d654884c9ce4 Mon Sep 17 00:00:00 2001 From: "gtm.daemon" Date: Wed, 16 Nov 2011 14:30:21 +0000 Subject: [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 --- iPhone/GTMUILocalizer.m | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'iPhone/GTMUILocalizer.m') 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 -- cgit v1.2.3