Last active
December 1, 2016 09:06
-
-
Save yycking/72bd2bdbff4dfd8afb0b28a358b93bab to your computer and use it in GitHub Desktop.
NSLocalizedString auto load Base.lproj if key not found
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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