Is there a way to define a custom path of where the strings for NSLocalizedString are read from? I am aware you can define what filename to read from, but I am trying to make a user-editable system that will be stored in the Application Support folder. If there is no way to change the path it reads from, then is there a low-level class built into cocoa to read localized string files?
A:
One thing you could do is re-define NSLocalizedString in your pre-compiled header (.pch) file to point to a class of your own like MyLocalizationHandler, as such:
#undef NSLocalizedString
#define NSLocalizedString(key,comment) [[MyLocalizationHandler sharedLocalizationHandler] localizedString:key]
and then in MyLocalizationHandler.m do something like:
- (NSString *)localizedString:(NSString *)key {
// lookup the key however we want...
NSString *value = [self lookupLocalizedKey:key];
if (value)
return value;
// and maybe fall-back to the default localized string loading
return [[NSBundle mainBundle] localizedStringForKey:key value:key table:nil];
}
mprudhom
2010-08-24 02:58:04