Last active
January 8, 2016 15:38
-
-
Save ipedro/645d202d48649fdc196c to your computer and use it in GitHub Desktop.
extract country display names in different languages
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
-(void)makeCountriesJSON | |
{ | |
NSArray<NSString*> *localeIds = @[@"pt", @"en"]; | |
NSArray<NSString*> *countryCodesArray = [NSLocale ISOCountryCodes]; | |
NSMutableString *json = [NSMutableString stringWithString:@"{"]; | |
[localeIds enumerateObjectsUsingBlock:^(NSString * localeId, NSUInteger localeIndex, BOOL * _Nonnull stop) { | |
NSLocale *locale = [NSLocale localeWithLocaleIdentifier:localeId]; | |
[json appendFormat:@"\"%@\": {", locale.localeIdentifier]; | |
[countryCodesArray enumerateObjectsUsingBlock:^(NSString *code, NSUInteger codeIndex, BOOL * _Nonnull stop) { | |
[json appendFormat:@"\"%@\":\"%@\"", code, [locale displayNameForKey:NSLocaleCountryCode value:code]]; | |
if (codeIndex < countryCodesArray.count-1) | |
{ | |
[json appendString:@","]; | |
} | |
}]; | |
[json appendString:@"}"]; | |
if (localeIndex < localeIds.count-1) | |
{ | |
[json appendString:@","]; | |
} | |
}]; | |
[json appendString:@"}"]; | |
NSLog(@"%@", json); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment