Localization of strings in static lib

前端 未结 3 1187
生来不讨喜
生来不讨喜 2021-02-02 02:12

I have a project that uses a static library (SL). In that SL, there are a couple of strings I\'d like to localize and the project includes all of the localization files. The loc

3条回答
  •  滥情空心
    2021-02-02 02:28

    It is not possible to bundle it in a static lib, but you can create new bundle like "MyStaticLibraryName.bundle", put inside all localizations and use the code below instead "NSLocalizedString()". All you need to do: add a static library and resource bundle.

    NSString *MyLocalizedString(NSString* key, NSString* comment) {
    static NSBundle* bundle = nil;
    if (!bundle) {
        NSString* path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"MyStaticLibraryName.bundle"];
        bundle = [[NSBundle bundleWithPath:path] retain];
    }
    
    return [bundle localizedStringForKey:key value:key table:nil];
    }
    

提交回复
热议问题