/*
Localizable_en.strings
*/
"NEWS" = "NEWS";
"CLASS" = "CLASS";
"GYM" = "GYM";
"SEARCH" = "SEARCH";
"MORE" = "MORE";
"CHANGE LANGUAGE" = "CHANGE LANGUAGE";
/*
Localizable_en.strings
*/
"NEWS" = "新闻";
"CLASS" = "课程";
"GYM" = "健身房";
"SEARCH" = "搜索";
"MORE" = "更多";
"CHANGE LANGUAGE" = "更改语言";
AppsDelegate
+ (NSString*)getCurrentLang {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *sLanguage = [defaults objectForKey:@"txtLanguage"];
if(sLanguage == nil) {
return @"EN";
}else{
return sLanguage;
}
}
+ (NSString*)getLocalizedTableName {
return [NSString stringWithFormat:@"Localizable_%@",[[self getCurrentLang]lowercaseString]];
}
+ (NSString*)getLocalizedText:(NSString*)toLocalize {
return NSLocalizedStringFromTable(toLocalize, [AppDelegate getLocalizedTableName], @"");
}
- (void)setupTabBar {
UITabBarController * tabBarController = (UITabBarController*)[self.window rootViewController];
if(tabBarController != nil) {
((UIViewController*)[tabBarController.viewControllers objectAtIndex:0]).tabBarItem.title = [AppDelegate getLocalizedText:@"CLASS"];
((UIViewController*)[tabBarController.viewControllers objectAtIndex:1]).tabBarItem.title = [AppDelegate getLocalizedText:@"NEWS"];
((UIViewController*)[tabBarController.viewControllers objectAtIndex:2]).tabBarItem.title = [AppDelegate getLocalizedText:@"GYM"];
((UIViewController*)[tabBarController.viewControllers objectAtIndex:3]).tabBarItem.title = [AppDelegate getLocalizedText:@"SEARCH"];
((UIViewController*)[tabBarController.viewControllers objectAtIndex:4]).tabBarItem.title = [AppDelegate getLocalizedText:@"MORE"];
}
}
ChangeLanguage.m
- (IBAction)btnEnglish:(id)sender {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@"EN" forKey:@"txtLanguage"];
[(AppDelegate*)[UIApplication sharedApplication].delegate setupTabBar];
UITabBarController * tabBarController = (UITabBarController*)[[[UIApplication sharedApplication] keyWindow] rootViewController];
tabBarController.selectedIndex = 0;
}