Skip to content

Instantly share code, notes, and snippets.

@wimhaanstra
Created October 20, 2011 19:39
Show Gist options
  • Save wimhaanstra/1302103 to your computer and use it in GitHub Desktop.
Save wimhaanstra/1302103 to your computer and use it in GitHub Desktop.
LocalizationHelper
//
// 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
//
// 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
@wimhaanstra
Copy link
Author

Added the .h file to the same Gist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment