Managing several hundred occurrences of NSLocalizedString
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")
#de开发者_开发技巧fine 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?
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
精彩评论