There are tricks such as creating a locale with an identifier, but instead of a normal locale identifier such as "en_US", pass the currency code "USD", "EUR", etc., it seems to work on eur and usd so that I could verify this, but this is not true. IMHO.
The only correct way that I know is to get all the locales, and then check the currency codes in a loop to compare them with the one you have. This way you stop the loop when you find your code.
- (NSLocale *) findLocaleByCurrencyCode:(NSString *)_currencyCode { NSArray *locales = [NSLocale availableLocaleIdentifiers]; NSLocale *locale = nil; NSString *localeId; for (localeId in locales) { locale = [[[NSLocale alloc] initWithLocaleIdentifier:localeId] autorelease]; NSString *code = [locale objectForKey:NSLocaleCurrencyCode]; if ([code isEqualToString:_currencyCode]) break; else locale = nil; } if (locale == nil) { NSDictionary *components = [NSDictionary dictionaryWithObject:_currencyCode forKey:NSLocaleCurrencyCode]; localeId = [NSLocale localeIdentifierFromComponents:components]; locale = [[NSLocale alloc] initWithLocaleIdentifier:localeId]; } return locale; }
Cynichniy bandera
source share