Last active
December 13, 2015 22:19
-
-
Save matthiaswenz/4984002 to your computer and use it in GitHub Desktop.
A simple category on NSDictionary which allows localized values for string-based keys, built for @bowstreet.
License: MIT - go on, have fun with it, but don't expect anything from us. You might ask politely, though - we're a nice bunch.
This file contains 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
#import <Foundation/Foundation.h> | |
@interface NSDictionary (Localized) | |
- (id)localizedValueForKey:(NSString *)aKey; | |
- (id)localizedValueForKey:(NSString *)aKey withLanguage:(NSString *)aLanguage; | |
@end |
This file contains 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
#import "NSDictionary+Localized.h" | |
@implementation NSDictionary (Localized) | |
static NSString *defaultLanguage = @"en"; | |
- (id)localizedValueForKey:(NSString *)aKey { | |
return [self localizedValueForKey:aKey withLanguage:defaultLanguage]; | |
} | |
- (id)localizedValueForKey:(NSString *)aKey withLanguage:(NSString *)aLanguage { | |
id value = [self valueForKey:[NSString stringWithFormat:@"%@_%@", aKey, aLanguage]]; | |
if (value != nil) { | |
return value; | |
} | |
return [self valueForKey:aKey]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment