我正在尝试使用NSLocalizedStringFromTable
,但没有结果。我已经创建了Profile.strings
文件,点击了本地化,在项目设置中我添加了波兰语和英语,所以我的文件里面有2个“文件”,我用其他值输入相同的字符串,但当我切换语言并重新启动时应用程序仍有一个本地化使用(波兰语)。
Xcode中的Profile.strings:
Profile.strings
Profile.strings (Polish)
Profile.strings (English)
抛光:
"fullName.placeholder" = "Imie i nazwisko";
"emailAddress.placeholder" = "Adres email";
"phoneNumber.placeholder" = "Numer telefonu";
英文:
"fullName.placeholder" = "Full name";
"emailAddress.placeholder" = "Email address";
"phoneNumber.placeholder" = "Phone number";
为了获得价值我打电话:
NSLocalizedStringFromTable(@"fullName.placeholder", @"Profile", @"");
每当我打电话给我时,我都会从Profile.strings (Polish)
我做错了什么?
答案 0 :(得分:6)
尝试重置内容和设置的模拟器,它将起作用(:
答案 1 :(得分:4)
也许你没有正确改变语言。尝试在代码中执行此操作。像这样:
- (void) setLanguage:(NSString*) l{
for (NSString *language1 in [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]) {
NSBundle *bundle1 = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language1 ofType:@"lproj"]];
NSLog(@"%@: %@", language1, NSLocalizedStringFromTableInBundle(@"left", @"Localizable", bundle1, nil));
}
NSBundle *bundle1 = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:l ofType:@"lproj"]];
/*
if ([l isEqualToString:@"en"]) {
bundle1 = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"English" ofType:@"lproj"]];
}
*/
if (bundle1 == nil)
//in case the language does not exists
[self resetLocalization];
else
bundle = bundle1;
NSMutableArray *langs = [NSMutableArray arrayWithArray: [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"]];
[langs removeObject:l];
NSMutableArray *newLangs = [NSMutableArray arrayWithObject:l];
[newLangs addObjectsFromArray:langs];
[[NSUserDefaults standardUserDefaults] setObject: newLangs forKey:@"AppleLanguages"];
}
然后你可以做
[self setLanguage:@"en"];