Re: "untitled" vs "Untitled" (code correction)
Re: "untitled" vs "Untitled" (code correction)
- Subject: Re: "untitled" vs "Untitled" (code correction)
- From: m <email@hidden>
- Date: Mon, 11 Jul 2005 18:00:06 -0700
For the archives:
I had posted an override for NSDocument's displayName method that
produces HIG compliant results for untitled documents. It's been
pointed out to me that all nouns are capitalized in German (and only
German apparently), despite efforts at reform <http://
en.wikipedia.org/wiki/German_spelling_reform>, so I modified the code
to account for this.
I make no claim that it will produce universally correct results, but
for localizations that are available in AppKit (Danish, Dutch,
English, Finnish, French, German, Italian, Japanese, Korean,
Norwegian, Portuguese, Spanish, Swedish, and Chinese), it appears to
work fine.
- (NSString *)displayName
{
NSString* displayName = [super displayName];
// Determine if this document was never saved.
// We do this by checking if the document has a file path. This is
// complicated (slightly) by the fact that NSDocument's fileURL
method
// is new in Tiger, and NSDocument's filePath is dperectaed in
Tiger.
BOOL neverSaved = NO;
if ([self methodForSelector:@selector(fileURL)])
{
neverSaved = [self fileURL] == nil;
}
else
{
neverSaved = [self fileName] == nil;
}
if (neverSaved)
{
// Special case for German.
// German is the only language in the world that
capitalizes
// all nouns, so our strategy of lowercasing would
produce the
// wrong result.
NSDictionary* userDefaults = [[NSUserDefaults
standardUserDefaults] dictionaryRepresentation];
NSArray* myLocalizations = [[NSBundle mainBundle]
localizations];
NSArray* preferredLocalizations = [NSBundle
preferredLocalizationsFromArray:myLocalizations forPreferences:
[userDefaults objectForKey:@"NSLanguages"]];
NSString* currentLanguage = [preferredLocalizations
objectAtIndex:0];
if (![currentLanguage isEqualTo:@"German"])
{
// Lowercase the displayName so that, for example,
// "Untitled 4" becomes "untitled 4".
displayName = [displayName lowercaseString];
}
}
return displayName;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden