My app contain two XIB files for English and Arabic language.I want to change the XIB files when language change without restarting the application.
Asked
Active
Viewed 4,744 times
1
-
i think you need to Detect current iPhone input language then according to that you can use your xib files. – jamil Jun 24 '13 at 07:58
-
possible duplicate of [How to change app language programmatically WITHOUT restarting my app?](http://stackoverflow.com/questions/15786501/how-to-change-app-language-programmatically-without-restarting-my-app) – rptwsthi Jun 27 '13 at 06:35
1 Answers
0
I have done same kind of task in my recent project Need to support Arabic & English. Where I need to change Language according selected option from list. I have created two .xib one for Arabic and one for english and then select
// for setting bundle
+(void) setContentBundle{
SS AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSString *currentLanguage;
if([delegate.strLanguage length]> 0)
{
currentLanguage = delegate.strLanguage;
}else {
currentLanguage = @"en";
}
if ([currentLanguage isEqualToString:@"ar"]) { // If ARABIC.
languageBundle = nil;
NSString* path = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];
languageBundle = [NSBundle bundleWithPath:path];
}else if ([currentLanguage isEqualToString:@"en"]){ // If ENGLISH.
languageBundle = nil;
NSString* path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
languageBundle = [NSBundle bundleWithPath:path];
}
}
// getting localiation key value
+(NSString *)getLocalizedStringForKey:(NSString *)key value:(NSString *)v table:(NSString *)t{
if([key isEqualToString:@"FollowUp.DepartmentKey"]){
NSLog(@"%@",key);
}
SSAppDelegate *delegate = (SSAppDelegate *)[UIApplication sharedApplication].delegate;
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"KEY LIKE[c] %@",
key];
NSArray *filteredArray = [delegate.arrSystemMessages filteredArrayUsingPredicate:predicate];
NSLog(@"%@", filteredArray);
if(filteredArray!=nil && [filteredArray count]>=1){
NSMutableDictionary *dict=[filteredArray objectAtIndex:0];
if([[ContentBundleManager selectLanguage] isEqualToString:@"ar"]){
return [dict valueForKey:@"AR"];
}else{
return [dict valueForKey:@"EN"];
}
}else{
return [[ContentBundleManager getContentBundle] localizedStringForKey:key value:v table:t];
}
}
//for getting bundle
+(NSBundle *) getContentBundle{
SSAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSString *currentLanguage;
if([delegate.strLanguage length]> 0)
{
currentLanguage = delegate.strLanguage;
}else {
currentLanguage = @"en";
}
if ([currentLanguage isEqualToString:@"ar"]) { // If ARABIC.
languageBundle = nil;
NSString* path = [[NSBundle mainBundle] pathForResource:@"ar" ofType:@"lproj"];
languageBundle = [NSBundle bundleWithPath:path];
}else if ([currentLanguage isEqualToString:@"en"]){ // If ENGLISH.
languageBundle = nil;
NSString* path = [[NSBundle mainBundle] pathForResource:@"en" ofType:@"lproj"];
languageBundle = [NSBundle bundleWithPath:path];
}
return languageBundle;
}
/// and call .xib
SSBaseViewController *baseView= [SSLBaseViewController getBaseViewObjectWithBundle:nil];
/// and call string file
[baseView setHeaderTitle:[ContentBundleManager getLocalizedStringForKey:@"FollowUp.FollowUpKey" value:@"" table:nil]];
-
-
content bundle is nothing but idea for fetching xib according selected language. Check +(void) setContentBundle it is doing same thing. – Mangesh Jun 24 '13 at 11:52
-
-