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).

  • The .strings file used by the NSPredicateEditor must 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 .strings file. (The sample, mentioned below, uses the NSLocalizedStringFromTable() macro to specify a custom strings file called Predicate.strings)

  • I’ve created an example project (which was the demo shown during my session at MacTech Conference 2010) to illustrate both creating a custom NSPredicateEditorRowTemplate and localizing the predicate editor. You can download it from my website:

  • Most of what learned regarding localizing NSPredicateEditor was gleaned from this email thread and the linked sample project.

  1. funwithobjc posted this
Short URL for this post:
blog comments powered by Disqus