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
.