I would like to localize my constants. Constants are defined and declared the usual way:
extern NSString * const kStringName;
NSString * const kStringName = @\"
Going the normal route by declaring with extern
in a header and defining in the implementation using NSLocalizedString()
results in this error:
Initializer element is not a compile-time constant
Here's one way to get around this problem.
In the header file declare a class method that returns a string...
@interface MyGlobals : NSObject
+ (NSString *)localizedStringWhatever;
@end
Implement the method...
@implementation MyGlobals
+ (NSString *)localizedStringWhatever {
return NSLocalizedString(@"Whatever", @"blah blah blah.");
}
@end
When you need to use it import MyGlobals
and ask it for the string...
NSString *whatever = [MyGlobals localizedStringWhatever];