Followup to Localizing NSPredicateEditor
To expand a little bit on my previous post, here’s a little bit more information:
If you ever forget the format to put in the
NSLocalizedString()macros, you can do the following:
predicateEditor = ... //an NSPredicateEditor NSData * stringsData = [predicateEditor _generateFormattingDictionaryStringsFile]; NSString * strings = [[NSString alloc] initWithData:stringsData encoding:NSUTF16StringEncoding]; [strings writeToFile:@"/path/to/Predicate.strings" encoding:NSUTF16StringEncoding error:nil]; [strings release];
This is relying on an undocumented method of
NSPredicateEditor, but will work fine to simply generate the strings data. As always, you should probably not use this in shipping code (especially with the imminent launch of the Mac App Store).
.stringsfile used by the
NSPredicateEditormust not contain any other localizations. In other words, you must use the file for localizing only the editor. If you need to localize other parts of your application, their strings must be in a separate
.stringsfile. (The sample, mentioned below, uses the
NSLocalizedStringFromTable()macro to specify a custom strings file called
I’ve created an example project (which was the demo shown during my session at MacTech Conference 2010) to illustrate both creating a custom
NSPredicateEditorRowTemplateand localizing the predicate editor. You can download it from my website: http://davedelong.com/portfolio
Most of what learned regarding localizing
NSPredicateEditorwas gleaned from this email thread and the linked sample project.