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]];
当语言改变时,它只显示字符串而非图像
答案 0 :(得分: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是环境变量。 我希望它对你有用。