0
if ([objGlobalUser.strAppLangID isEqualToString:[@"en" uppercaseString]]) {
    objGlobalUser.strLanguage =@"en";

    [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:objGlobalUser.strLanguage, nil] forKey:@"AppleLanguages"];
    [[NSUserDefaults standardUserDefaults] synchronize];

    NSLog(@"preferredLang: %@", objGlobalUser.strLanguage);        
} else {
    objGlobalUser.strLanguage =@"ar";
    [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:objGlobalUser.strLanguage, nil] forKey:@"AppleLanguages"];
    [[NSUserDefaults standardUserDefaults] synchronize];
}       

NSString *path= [[ NSBundle mainBundle ] pathForResource:objGlobalUser.strLanguage ofType:@"lproj" ];

self.viewController = [[MyViewController alloc] initWithNibName:@"MyViewController"
                                                         bundle:[NSBundle bundleWithPath:path]];

语言更改时仅显示字符串而不显示图像

4

1 回答 1

0

至于我,我已经在 main.m 中完成了所有本地化操作,并且效果很好。这是一个例子:

//Localization Language setup

typedef enum {
    LLAuto = 0,
    LLEnglish = 1,
    LLFrench = 2,
    LLJapanese = 3,
    LLSpanish = 4
} TLocalizationLanguage;

static NSString * const LocalizationLanguages[] = {
    @"auto", @"en", @"fr", @"ja", @"es"
};

void setupLocalizationLanguage() {
    TLocalizationLanguage UsedLng = (TLocalizationLanguage) USE_LOCALIZATION_LANGUAGE;

    if (UsedLng == LLAuto) {
        [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"];
    } else {
        [[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:LocalizationLanguages[UsedLng], nil] forKey:@"AppleLanguages"];
    }

    [[NSUserDefaults standardUserDefaults] synchronize];

    NSLog(@"Use localization language: %@", LocalizationLanguages[UsedLng]);
}

// -------------------------------------------------------------------------------

#import "AppDelegate.h"

int main(int argc, char *argv[])
{
    @autoreleasepool {
        setupLocalizationLanguage();
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

其中 USE_LOCALIZATION_LANGUAGE 是一个环境变量。我希望它对你有用。

于 2013-06-24T07:32:33.110 回答