[英]NSLocalizedStringFromTable doesn't work
I'm trying to use NSLocalizedStringFromTable
but with no results. 我正在尝试使用
NSLocalizedStringFromTable
但没有结果。 I've got created Profile.strings
file, clicked localized, in project settings I add Polish and English languages, so my file has 2 "files" inside and I typed the same strings with other values but when I switch languages and restart app there is still one localization used (Polish). 我已经创建了
Profile.strings
文件,点击了本地化,在项目设置中我添加了波兰语和英语,所以我的文件里面有2个“文件”,我输入了相同的字符串和其他值,但当我切换语言并重新启动app时仍然是一个本地化使用(波兰语)。
Profile.strings in Xcode: Xcode中的Profile.strings:
Profile.strings
Profile.strings (Polish)
Profile.strings (English)
Polish: 抛光:
"fullName.placeholder" = "Imie i nazwisko";
"emailAddress.placeholder" = "Adres email";
"phoneNumber.placeholder" = "Numer telefonu";
English: 英语:
"fullName.placeholder" = "Full name";
"emailAddress.placeholder" = "Email address";
"phoneNumber.placeholder" = "Phone number";
To get value I call: 为了获得价值我打电话:
NSLocalizedStringFromTable(@"fullName.placeholder", @"Profile", @"");
Any time I call this I've got value from Profile.strings (Polish)
任何时候我称之为我从
Profile.strings (Polish)
获得价值
What I'm doing wrong? 我做错了什么?
尝试重置模拟器的内容和设置它将起作用(:
Maybe you're not changing the language correctly. 也许你没有正确改变语言。 Try doing it in code.
尝试在代码中执行此操作。 Like this:
像这样:
- (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"];
}
And then you can do 然后你就可以做到
[self setLanguage:@"en"];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.