Created
October 20, 2011 19:39
-
-
Save wimhaanstra/1302103 to your computer and use it in GitHub Desktop.
LocalizationHelper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LocalizationHelper.h | |
// | |
// Created by Wim Haanstra on 9/30/10. | |
// Copyright 2010 Wim Haanstra. All rights reserved. | |
// | |
#import | |
@interface LocalizationHelper : NSObject { } | |
+ (void) localizeView:(UIView*) view; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// LocalizationHelper.m | |
// | |
// Created by Wim Haanstra on 9/30/10. | |
// Copyright 2010 Wim Haanstra. All rights reserved. | |
// | |
#import "LocalizationHelper.h" | |
@implementation LocalizationHelper | |
+ (void) localizeView:(UIView*) view | |
{ | |
for (UIView* subView in view.subviews) | |
{ | |
if ([subView isKindOfClass:[UIButton class]]) | |
{ | |
UIButton* castButton = (UIButton*) subView; | |
[castButton setTitle:NSLocalizedString([castButton titleForState:UIControlStateNormal], [castButton titleForState:UIControlStateNormal]) forState:UIControlStateNormal]; | |
} | |
else if ([subView isKindOfClass:[UITextField class]]) | |
{ | |
UITextField* castField = (UITextField*) subView; | |
[castField setPlaceholder:NSLocalizedString(castField.placeholder, castField.placeholder)]; | |
} | |
else if ([subView isKindOfClass:[UILabel class]]) | |
{ | |
UILabel* castLabel = (UILabel*) subView; | |
[castLabel setText:NSLocalizedString(castLabel.text, castLabel.text)]; | |
} | |
else if ([subView isKindOfClass:[UISegmentedControl class]]) | |
{ | |
UISegmentedControl* castSC = (UISegmentedControl*) subView; | |
for (int index = 0; index < castSC.numberOfSegments; index++) | |
{ | |
NSString* title = [castSC titleForSegmentAtIndex:index]; | |
[castSC setTitle:NSLocalizedString(title, title) forSegmentAtIndex:index]; | |
} | |
} | |
else if ([subView isKindOfClass:[UITabBarController class]]) | |
{ | |
NSLog(@"Tabbar controller found!"); | |
} | |
else if ([subView isKindOfClass:[UITabBar class]]) | |
{ | |
UITabBar* tabBar = (UITabBar*) subView; | |
NSArray* tabBarItems = tabBar.items; | |
for (UITabBarItem* item in tabBarItems) | |
{ | |
NSString* title = item.title; | |
[item setTitle:NSLocalizedString(title, title)]; | |
} | |
continue; | |
} | |
[self localizeView:subView]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Added the .h file to the same Gist