1

私のアプリには、英語とアラビア語の 2 つの XIB ファイルが含まれています。言語が変更されたときに、アプリケーションを再起動せずに XIB ファイルを変更したいと考えています。

4

1 に答える 1

0

最近のプロジェクトで同じ種類のタスクを実行しました。アラビア語と英語をサポートする必要があります。リストから選択したオプションに従って言語を変更する必要がある場所。アラビア語用と英語用の 2 つの .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 に答える