Skip to content

Instantly share code, notes, and snippets.

@virasio
Created August 4, 2014 19:23
Show Gist options
  • Save virasio/c026c414e9bcfd73464a to your computer and use it in GitHub Desktop.
Save virasio/c026c414e9bcfd73464a to your computer and use it in GitHub Desktop.
@interface NSLocale (Utilities)
@property (nonatomic, readonly) NSDictionary *ISOLanguages;
+ (NSString *)getCountryNameForCode:(NSString *)countryCode;
+ (NSString *)getLanguageNameForCode:(NSString *)languageCode;
+ (NSString *)getLocalizedLanguageNameForCode:(NSString *)languageCode
@end
#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