开发者

NSLocalizedString Path

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-开发者_Go百科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?


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];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜