Bug 6599 - NSLocale.DisplayNameForKey missing in MonoTouch
Summary: NSLocale.DisplayNameForKey missing in MonoTouch
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: 5.2
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2012-08-18 17:53 UTC by Bryan Moulton
Modified: 2012-08-31 16:28 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description Bryan Moulton 2012-08-18 17:53:35 UTC
The DisplayNameForKey function is missing from NSLocale, and isn't anywhere to be found in the MonoTouch documentation.

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSLocale_Class/Reference/Reference.html#//apple_ref/occ/instm/NSLocale/displayNameForKey:value
Comment 1 Sebastien Pouliot 2012-08-19 19:11:10 UTC
DisplayNameForKey is available but the method itself is internal. This happens when better, more .net-ish, API are provided (e.g. to avoid dealing with NSString constants the too comon typos when using them).

So the replace it NSLocale provides a few methods such as:

* GetIdentifierDisplayName
* GetLanguageCodeDisplayName
* GetCountryCodeDisplayName

which in turns calls the (internal) DisplayNameForKey with the right constant.
Comment 2 Bryan Moulton 2012-08-22 13:25:10 UTC
A customer is trying to use NSLocaleCurrencyCode. Would it be possible to add a GetCurrencyDisplayName function?
Comment 3 Sebastien Pouliot 2012-08-22 16:05:19 UTC
Not sure that's supported. E.g.

NSLocale en = new NSLocale ("en-US");
Console.WriteLine (en.CurrencySymbol ?? "null");
Console.WriteLine (en.GetCurrencySymbolDisplayName (en.CurrencySymbol) ?? "null");

prints

$
null

Can you elaborate on what's required ?
Comment 5 Sebastien Pouliot 2012-08-31 15:09:37 UTC
The stackoverflow question (and answer) is about the current code "USD", not display name (which would be, I guess, "US dollar", but that's not something the API returns AFAIK).

SO's answer uses `objectForKey` which in MonoTouch is mapped to the NSLocale properties. So:

new NSLocale ("en-US").CurrencyCode == "USD"

`displayNameForKey` is not the same (but it do share some constants with objectForKey).
Comment 6 Bryan Moulton 2012-08-31 15:18:02 UTC
Not currency code, currency display name. The output should be "US Dollars" hence:

usd = [locale displayNameForKey:NSLocaleCurrencyCode value:@"USD"];

I referenced the wrong example there, sorry!
Comment 7 Sebastien Pouliot 2012-08-31 16:26:34 UTC
Ah, get you now :-) I made a CurrencySymbol vs CurrencyCode mistake in comment #3 - but you're right this one (and maybe others) do have a DisplayName.
Comment 8 Sebastien Pouliot 2012-08-31 16:28:34 UTC
Other constants returns null (or errors) so only GetCurrencyCodeDisplayName was added.

Fixed in 
master: 0625bb5611557362c19d9aff0d218d8f20862695
monotouch-5.4-series: 9ba3998148c32679a142e2a6a106b66510c12a8e

QA: unit tests added in master

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.


Create a new report for Bug 6599 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments


Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Related Links: