我想以此来本地化stringWithFormat:
NSString *string = [NSString stringWithFormat:@"Login %d in",2013];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@string, nil)
message:@"Message"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"sure", nil];
[alertView show];
我也写在Localizable.string中:
"Login %d in" = "LOGIN %d IN";
而且它不起作用。能帮我吗?谢谢...
最佳答案
您必须本地化格式字符串本身。做任何其他事情都没有意义,因为格式化后的字符串实际上可以是任何东西(毕竟这是格式化字符串的目的)。只是出于好奇,你没看过像
"%d seconds remaining" = "%d secondes restants";
"Hello, %@!" = "Bonjour, %@ !";
在您使用过的应用程序的
Localizable.strings
文件中吗?NSString *localizedFmt = NSLocalizedString(@"Login %d in", nil);
UIAlertView *av = [[UIAlertView alloc]
initWithTitle:[NSString stringWithFormat:localizedFmt, 2013],
// etc...
];
安全性怪胎的通知:尽管这是,它是本地化格式化字符串的最常用和最简单的方法,但这并不完全安全。
攻击者可以将应用程序的上述
Localizable.strings
文件中的本地化格式字符串更改为伪造的内容,例如,更改为包含比stringWithFormat:
具有参数更多的转换说明符的字符串(甚至不匹配的说明符-将整数视为指针,有人吗?),然后可以对您的应用程序进行基于堆栈粉碎的攻击-因此要当心黑客。
关于ios - 我想通过stringWithFormat本地化的iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17961274/