Created
August 4, 2014 19:23
-
-
Save virasio/c026c414e9bcfd73464a to your computer and use it in GitHub Desktop.
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
@interface NSLocale (Utilities) | |
@property (nonatomic, readonly) NSDictionary *ISOLanguages; | |
+ (NSString *)getCountryNameForCode:(NSString *)countryCode; | |
+ (NSString *)getLanguageNameForCode:(NSString *)languageCode; | |
+ (NSString *)getLocalizedLanguageNameForCode:(NSString *)languageCode | |
@end |
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
#import "NSLocale+Utilities.h" | |
@implementation NSString (Utilities) | |
+ (NSDictionary *)ISOLanguages { | |
NSArray *languageCodes = [NSLocale ISOLanguageCodes]; | |
NSMutableDictionary *languages = [NSMutableDictionary new]; | |
for(NSString *languageCode in languageCodes) { | |
languages[languageCode.uppercaseString] = [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:languageCode]; | |
} | |
return [languages copy]; | |
} | |
+ (NSString *)getCountryNameForCode:(NSString *)countryCode { | |
return [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:countryCode]; | |
} | |
+ (NSString *)getLanguageNameForCode:(NSString *)languageCode { | |
return [[NSLocale currentLocale] displayNameForKey:NSLocaleIdentifier value:[languageCode lowercaseString]]; | |
} | |
+ (NSString *)getLocalizedLanguageNameForCode:(NSString *)languageCode { | |
NSLocale *locale = [NSLocale localeWithLocaleIdentifier: | |
[NSLocale canonicalLocaleIdentifierFromString:languageCode]]; | |
return [locale displayNameForKey:NSLocaleIdentifier value:[languageCode lowercaseString]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment