Skip to content

Instantly share code, notes, and snippets.

@yycking
Last active December 1, 2016 09:06
Show Gist options
  • Save yycking/72bd2bdbff4dfd8afb0b28a358b93bab to your computer and use it in GitHub Desktop.
Save yycking/72bd2bdbff4dfd8afb0b28a358b93bab to your computer and use it in GitHub Desktop.
NSLocalizedString auto load Base.lproj if key not found
#ifndef L
#define L(key) [NSBundle.mainBundle localizedStringForKey:(key)]
#endif
@interface NSBundle (NSLocalizedString_Base)
- (NSString *)localizedStringForKey:(NSString *)key;
@end
@implementation NSBundle (NSLocalizedString_Base)
- (NSString *)localizedStringForKey:(NSString *)key {
NSString * s = [self localizedStringForKey:key value:@"" table:nil];
if ([s isEqualToString:key]) {
NSString * path = [[NSBundle mainBundle] pathForResource:@"Base" ofType:@"lproj"];
NSBundle * languageBundle = [NSBundle bundleWithPath:path];
s = [languageBundle localizedStringForKey:key value:@"" table:nil];
}
if (s == nil) {
s = key;
}
return s;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment