I have added this file in my project with the code:
Language.h:
@interface Language : UIViewController
@end
@implementation Language
static NSBundle *bundle = nil;
+(void)setLanguage:(NSString *)l {
NSLog(@"preferredLang: %@", l);
NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
bundle = [[NSBundle bundleWithPath:path] retain];
}
+(void)initialize {
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString *current = [[languages objectAtIndex:0] retain];
[self setLanguage:current];
}
Here this method +(NSString *)get: is not getting called
+(NSString *)get:(NSString *)key alter:(NSString *)alternate {
NSLog(@"Bundle path: %@", [bundle bundlePath]);
return [bundle localizedStringForKey:key value:alternate table:nil];
}
@end
And in my viewController.m file where I have two buttons for change of language Turkish and English Language:
-(IBAction)englishLang:(id)sender{
[Language setLanguage:@"en"];
NSLog(@"language to english");
}
-(IBAction)turkishLang:(id)sender{
[Language setLanguage:@"tr"];
NSLog(@"language to turkish");
}
The issue is when I click on turkish lang button, the language should be changed and the next nib file should be turkish localized, picked up by the application. But I am not getting that behavior from my application.
It only loads the english localized nib file.
What can be the issue ?
If you want to use an app language that isnt based on the phones language you need to do a couple of things:
string based on your language, not the phones (it sounds like this is the main problem, if you have NSLocalizedStrings through the app, the value returned will only ever be the same as the language of the phone)