Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to handle scenarios where the Language and Region are different?

GlayzuGlayzu IEMember ✭✭

In the settings the device language is set to 'English', and the region is set to 'Denmark'. It seems like this combination leads to the culture defaulting to 'en-US'. Which then causes issues when a user inputs numeric values with a decimal place. Denmark using ',' separator, while the US uses a point. So '1,99' becomes '199.00' once parsed..

One thing I had considered is mapping NSLocale to CultureInfo, but NSLocale gives me a CountryCode of 'DK' while CultureInfo would require 'da-DK'. So I don't think that'll work as I want to support all regions.

The second is to change all numeric inputs to string, and then use the NSLocale.CurrentLocale.DecimalSeparator and NSLocale.CurrentLocale.GroupSeparator to format all strings back to 'en-US'. I would also then have to format all outputs as such too though.

I'm hoping there's an easier way around this!

Answers

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    It should be noted that the identifier returned by NSLocaleCountryCode will be the user's "region format". The language has nothing to do with this. So if you do want to implement it , the second way seems better .

  • GlayzuGlayzu IEMember ✭✭

    @LucasZhang said:
    It should be noted that the identifier returned by NSLocaleCountryCode will be the user's "region format". The language has nothing to do with this. So if you do want to implement it , the second way seems better .

    Thanks, I appreciate that the Region Format and Language are separate. I was hoping for an easier solution for handling this scenario! As the second approach involves changing all my numeric values into strings, and casting these back and forth.

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    Apple officials did not provide such a method .So you need to implement it by yourself .

  • GlayzuGlayzu IEMember ✭✭

    @LucasZhang said:
    Apple officials did not provide such a method .So you need to implement it by yourself .

    Thanks, that'd be because iOS allows a user to input separate Region/Language which Mono doesn't recognise and defaults to 'en-US'. I wouldn't expect Apple to add support to Mono! https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/localization/

    So best solution is to convert all numeric inputs to string, and use the NSLocale.CurrentLocale.DecimalSeparator to determine which decimal separator to display to the user. In the core this decimal separator would still be based off the CultureInfo.NumberFormat.NumberDecimalSeparator, to avoid confusion.

Sign In or Register to comment.