2013-06-24 36 views
1

我的应用程序包含两个用于英语和阿拉伯语的XIB文件。我想在语言更改时更改XIB文件而无需重新启动应用程序。如何在不重新启动应用程序的情况下更改ios中的语言?

+0

我认为你需要检测当前iPhone的输入语言

文件。 – jamil

+0

可能的重复[如何以编程方式更改应用程序语言而无需重新启动我的应用程序?](http://stackoverflow.com/questions/15786501/how-to-change-app-language-programmatically-without-restarting-my-app) – rptwsthi

回答

0

我在我最近的项目中完成了同样的任务需要支持阿拉伯文&英文。我需要根据列表中选定的选项更改语言。我已经创建了两个的.xib一个阿拉伯文和一个用于英语,然后选择//用于再根据您可以使用您的厦门国际银行设置捆绑

+(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]]; 
+0

语言捆绑获取错误 – Neha

+0

如何在ios中设置ContentBundleManager? – Neha

+0

内容包不过是根据所选语言获取xib的想法。检查+(无效)setContentBundle它是做同样的事情。 – Mangesh

相关问题