我的应用程序包含两个用于英语和阿拉伯语的 XIB 文件。我想在语言更改时更改 XIB 文件而不重新启动应用程序。
问问题
4738 次
1 回答
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]];
于 2013-06-24T08:33:45.880 回答