dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.44k stars 4.76k forks source link

.NET 9 iOS / HybridGlobalization: currency symbols / currency names not available #108958

Open tipa opened 1 month ago

tipa commented 1 month ago

Description

With .NET 9, the current currency symbol / currency code are not available any more / replaced by the generic currency symbol

Reproduction Steps

Expected behavior

var a = RegionInfo.CurrentRegion.CurrencyEnglishName; // USD
var b = RegionInfo.CurrentRegion.ISOCurrencySymbol; // USD
var c = RegionInfo.CurrentRegion.CurrencyNativeName; // USD
var d = RegionInfo.CurrentRegion.CurrencySymbol; // $
var e = CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol; // $

Actual behavior

var a = RegionInfo.CurrentRegion.CurrencyEnglishName; // empty string
var b = RegionInfo.CurrentRegion.ISOCurrencySymbol; // empty string
var c = RegionInfo.CurrentRegion.CurrencyNativeName; // empty string
var d = RegionInfo.CurrentRegion.CurrencySymbol; // ¤
var e = CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol; // ¤

Regression?

Yes, it worked in .NET 8, even with HybridGlobalization=true

Known Workarounds

I can just use the iOS methods NSLocale.CurrentLocale.CurrencySymbol or NSLocale.CurrentLocale.CurrencyCode

Configuration

.NET 9 RC2 iPhone SE 2 (system language German)

Other information

No response

dotnet-policy-service[bot] commented 1 month ago

Tagging subscribers to this area: @dotnet/area-system-globalization See info in area-owners.md if you want to be subscribed.

dotnet-policy-service[bot] commented 1 month ago

Tagging subscribers to 'os-ios': @vitek-karas, @kotlarmilos, @ivanpovazan, @steveisok, @akoeplinger See info in area-owners.md if you want to be subscribed.

tarekgh commented 1 month ago

cc @matouskozak

matouskozak commented 1 month ago

@tipa what culture is your application using?

I see the correct output after setting the culture to en-US.

tipa commented 1 month ago

@matouskozak I see these results:

CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol  -> ¤
CultureInfo.CurrentCulture.Name  -> "en"
new CultureInfo("en-US").NumberFormat.CurrencySymbol -> $
new CultureInfo("de-DE").NumberFormat.CurrencySymbol -> €
new CultureInfo("en").NumberFormat.CurrencySymbol -> ¤

Is this the expected behaviour?

matouskozak commented 1 month ago

I think en is a "neutral" culture code. You can set the specific culture (en-US) using https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.defaultthreadcurrentculture?view=net-9.0 and it should work as expected.

tipa commented 1 month ago

I don't (want to) set the current culture myself - and I don't know the users culture (region). My use-case was to show a default currency symbol in my app, that the user could edit. Previously (.NET 8, even with HybridGlobalization=true) my code returned a $ for US users, probably because CultureInfo.CurrentCulture did not return a neutral culture. If this was an expected change, then that's ok and we can close this issue :) I have my workaround with NSLocale.CurrentLocale.CurrencySymbol anyways

matouskozak commented 1 month ago

I don't (want to) set the current culture myself - and I don't know the users culture (region). My use-case was to show a default currency symbol in my app, that the user could edit. Previously (.NET 8, even with HybridGlobalization=true) my code returned a $ for US users, probably because CultureInfo.CurrentCulture did not return a neutral culture. If this was an expected change, then that's ok and we can close this issue :) I have my workaround with NSLocale.CurrentLocale.CurrencySymbol anyways

I think it is not expected change, and we should investigate.