Reputation: 2701
How do I change my applications default language within my application? I am trying to change my applications language to Arabic, and I'm not sure how to accomplish this.
Upvotes: 2
Views: 274
Reputation: 3274
There is a way:
First make a different folder named as ar.lproj
and put localizable.String
May following sample code help you. You can call this function in viewWillAppear
with the key for which you need to get value.
-(NSString*) languageSelectedStringForKey:(NSString*) key
{
NSString *path;
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
if([[userDefault valueForKey:@"language_Selected"] intValue] == 0)
path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
else if([[userDefault valueForKey:@"language_Selected"] intValue] == 1)
path = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
NSString* str=[[languageBundle localizedStringForKey:key value:@"" table:nil] retain];
return str;
}
Hope you will understand the concept.
Upvotes: 4