Apple 是否为 NSError 的常见 NSButton 标题提供本地化恢复选项?
Apple 是否为常见 NSButton 标题提供本地化字符串,例如相当于 OK、Cancel、Try Again 和 Quit嗯>?
我正在尝试从另一个 Cocoa 框架交给我的一个自定义 NSError 对象中创建一个。我想实现 NSErrorRecoveryAttempting
非正式协议,让用户在发生错误时重试或退出。举个(简短的)例子:
NSString *cachesDir = ...;
NSError *error = nil;
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:cachesDir withIntermediateDirectories:NO attributes:nil error:&error];
// Failed creating the directory.
if (!success)
{
NSMutableDictionary *errorUserInfoCopy = [[[error userInfo] mutableCopy] autorelease];
NSArray *recoveryOptions = [NSArray arrayWithObjects:@"Try Again", @"Quit", nil];
[errorUserInfoCopy setObject:recoveryOptions forKey:NSLocalizedRecoveryOptionsErrorKey];
NSError *newError = [NSError errorWithDomain:[error domain] code:[error code] userInfo:errorUserInfoCopy];
[NSApp presentError:newError];
}
在第 10 行,NSArray *recoveryOptions = ...
,Apple 是否提供了一种轻松获取 Try Again/Quit 本地化版本(以及其他常见 NSButton 标题)的方法?或者我必须手动填充 .strings
文件并使用 NSLocalizedString()
代替?
Apple 确实为非自定义 NSError 提供了本地化恢复选项:
NSArray *recoveryOptions = [anError localizedRecoverySuggestion];
但这通常只是默认为本地化的“OK”。它不适合自定义 NSErrorRecoveryAttempting
。
Does Apple provide localized strings for common NSButton titles, such as the equivalents to OK, Cancel, Try Again, and Quit?
I'm attempting to create a custom NSError object from one handed to me by another Cocoa framework. I want to implement the NSErrorRecoveryAttempting
informal protocol to let the user Try Again or Quit if an error occurs. For (brief) example:
NSString *cachesDir = ...;
NSError *error = nil;
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:cachesDir withIntermediateDirectories:NO attributes:nil error:&error];
// Failed creating the directory.
if (!success)
{
NSMutableDictionary *errorUserInfoCopy = [[[error userInfo] mutableCopy] autorelease];
NSArray *recoveryOptions = [NSArray arrayWithObjects:@"Try Again", @"Quit", nil];
[errorUserInfoCopy setObject:recoveryOptions forKey:NSLocalizedRecoveryOptionsErrorKey];
NSError *newError = [NSError errorWithDomain:[error domain] code:[error code] userInfo:errorUserInfoCopy];
[NSApp presentError:newError];
}
In line 10, NSArray *recoveryOptions = ...
, does Apple provide a way to easily get localized versions of Try Again/Quit (among other common NSButton titles)? Or must I manually populate .strings
files and use NSLocalizedString()
instead?
Apple does provide localized recovery options for non-customized NSError's:
NSArray *recoveryOptions = [anError localizedRecoverySuggestion];
But this usually just defaults to a localized "OK". It's not suitable for custom NSErrorRecoveryAttempting
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
苹果似乎没有。
It appears that Apple does not.