views:

180

answers:

1

My application has several hundred points of localisation, some of which can be reused many times. To prevent from hunting and pecking through code to find occurrences of a particular NSLocalizedString, I create a macro for each in a header file using the #define preprocessor directive. For example:

#define kLocFirstString  NSLocalizedString(@"Default Text", @"Comment")
#define kLocSecondString NSLocalizedString(@"More Text", @"Another comment")
...

When I want to refer to a particular string, I do so by its macro name. This method has been working nicely for me, but I'm concerned that such blatant abuse of #define is frowned upon. From the standpoint of "correctness", should I just inline each NSLocalizedString with the code, or is there another method (extern NSString *aString; perhaps?) that I can use to collect the declarations in one place?

A: 

Apple provide the genstrings utility that can generate your strings file directly from the source code automatically. This means you can probably just inline your NSLocalizedStrings.

http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/genstrings.1.html

JeremyP
True, although there'd be a degree of repetition with a number of strings. My main concern was that my current implementation was against best practices, but Jason's response confirmed that it's ok.
Gordon Hughes
Yes, I agree, there is nothing wrong with your original approach. I tend to use the approach I described because it is as per the Apple guidelines.NB genstrings is clever enough to remove repeated strings.
JeremyP