ios - 我想通过stringWithFormat本地化的iOS

标签 ios localization

我想以此来本地化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/

相关文章:

iOS 网页滚动问题

ios - 隐藏 UINavigationBar 和状态栏问题

ios - UISegmentedControl 中的多个段选择

iOS6测试版和继续开发

ios - 当我拖动 UIImageView 时,在拖动过程中想要与同一 View 上显示的其他 imageView 进行比较

swift - 在 iOS 中本地化字符串

Django 1.9 sr_Latn 语言环境不起作用

ruby-on-rails - 适用于 Rails 3.2 的 L10N 解决方案

python - 如何从 Django URL 更改语言?

objective-c - 在资源中移动 .lproj 文件