开发者

NSLocalizedString Path

开发者 https://www.devze.com 2023-01-12 06:56 出处:网络
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百科edita

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

精彩评论

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

关注公众号