Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Currency Symbol and Currency Code based on ISOCountryCode
    text
    copied!<p>There are similar questions to this one from newbies like me in localization, but I couldn't find one that does the trick for me.</p> <p>Here is my problem. We can get all the ISO country codes in an NSArray with a statement of the form <code>[NSLocale ISOCountryCodes]</code>. Now, for each and every country of those I would like to print the local currency as well as the currency code used in that country. What would be the appropriate way of doing this?</p> <p>I did the following that does not work in the sense that I get lines of the form US United States: (null) ((null)) when instead I would like to get lines of the form US United States: $ (USD):</p> <pre><code>myCountryCode = [[NSLocale ISOCountryCodes] objectAtIndex:row]; appLocale = [[NSLocale alloc] initWithLocaleIdentifier: @"en_US"]; identifier = [NSLocale localeIdentifierFromComponents: [NSDictionary dictionaryWithObject: myCountryCode forKey: NSLocaleCountryCode]]; myDictionary = [NSLocale componentsFromLocaleIdentifier: identifier]; myCountryName = [appLocale displayNameForKey:NSLocaleCountryCode value:[myDictionary objectForKey:NSLocaleCountryCode]]; localCurrencySymbol = [appLocale displayNameForKey:NSLocaleCurrencySymbol value:[myDictionary objectForKey:NSLocaleCurrencySymbol]]; currencyCode = [appLocale displayNameForKey:NSLocaleCurrencyCode value: [myDictionary objectForKey:NSLocaleCurrencyCode]]; title = [NSString stringWithFormat:@"%@ %@: %@ (%@)", myCountryCode, myCountryName, localCurrencySymbol, currencyCode]; [appLocale release]; </code></pre> <p>(Above identifier, myCountryCode, myCountryName, localCurrencySymbol, currencyCode, and title are all NSString pointers. Moreover myDictionary is an NSDictionary pointer and appLocale is an NSLocale pointer). Essentially the above code will be in a pickerview where I want to generate the title of each line on the fly. </p> <p>Thank you very much for your time. Essentially the question is once we have the ISO country code how can we print (in the application locale) the currency symbol and the currency code for that specific country.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload