Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think your problem here is that you are expecting that <code>componentsFromLocaleIdentifer</code> will return information about the locale. Instead, it returns information about the string that is passed in as the identifier. Although you can receive NSLocalCurrencySymbol, it will only be present when the string that you are passing in has an override for the particular currency (which will never happen in your case, since you are only using the standard array). An example of this in the wild would be a user who has set up a FR system, but with a USD currency.</p> <p>Generally, you shouldn't need to use <code>-displayNameForKey:value:</code> for the <code>NSLocaleCurrencyCode</code> and <code>NSLocaleCurrencySymbol</code>, since they both return international strings, not localized strings. Thus, once you have the preferred local, you should be able to get this information just by using <code>-objectForKey:</code>.</p> <p>The tricky part, in my testing, is that assuming that the locale in the list is sufficient to create a valid currency code and symbol isn't true, instead you need to have a language and country code. Fortunately, <code>+[NSLocale canonicalLanguageIdentifierFromString:]</code> will provide you the right language, which you can then append to the country code (after a <code>_</code>) to create the country/language string that will appropriately result in the currency information being retrieved.</p> <p>Here's my revised code:</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:[myDictionaryobjectForKey:NSLocaleCountryCode]]; // Create the currency language combination and then make our locale NSString *currencyLocaleLanguage= [NSLocale canonicalLanguageIdentifierFromString: myCountryCode]; NSString *countryLanguage= [NSString stringWithFormat: @"%@_%@", myCountryCode, currencyLocaleLanguage]; NSLocale *currencyLocale = [[NSLocale alloc] initWithLocaleIdentifier: countryLanguage]; localCurrencySymbol = [currencyLocale objectForKey:NSLocaleCurrencySymbol]; currencyCode = [currencyLocale objectForKey:NSLocaleCurrencyCode]; title = [NSString stringWithFormat:@"%@ %@: %@ (%@)", myCountryCode, myCountryName, localCurrencySymbol, currencyCode]; [currencyLocale release]; [appLocale release]; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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