TextExpander NSLocalizedString Snippet

TextExpander is one of those apps I use so much on my Mac that I only notice when it’s not there. One thing I’ve been using it for a lot the last few days is fixing places in my code where I forgot to use NSLocalizedString and should have. If you’re not familiar, NSLocalizedString is a macro that Cocoa developers use for making strings localizable, which means the ability to display in the correct language for the user in cases where the app has the text for that translation.

So, if I see something like this in my code: self.title = @"Edit Bookmark", and I want to change it to this: self.title = NSLocalizedString(@"Edit Bookmark", @"Edit bookmark view title"), I cut the entire string and type ;lcl to trigger the snippet (you can make that whatever you want), which automatically pastes the corrected text back into the same location.

The snippet itself looks like this: NSLocalizedString(%clipboard, @"%|"). What it does is paste the contents of the clipboard (my string) into the first parameter, and puts the cursor into between the quotes of the second parameter so I can type out my comment.

Collin Donnell @collin