How can I force Localization Culture to en-US for whole application in Xamarin - iOS

How to force Xamain - iOS to work in US English culture regardless of user setting. The issue I am facing in my application is, The app only support US/UK English, But if the user changes the langue preference to Spanish , German etc. The number date etc format will change.

For Example, 2.35 will represent in Spanish, German as 2,35.

So if the user try to use the application with similar language, the app will miss behave or crash. Crash will occur in situation like when I try for Convert.ToDouble("2,35"); or similar.

So my doubt is,

Is it possible in Xamarin to forcefully set the culture as en-US. May be in one place, otherwise I need to change it all the places I performing Conversion.

Please help.

Tagged:

Posts

  • n.kuznetsovn.kuznetsov USUniversity ✭✭
    edited January 2016

    Hello, is there any update on this, were you able to get this working?

  • rschmidtrschmidt USMember ✭✭

    Running this code in your AppDelegate's FinishedLaunching method should do it:

    Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

    I don't know how the app store reviewers would feel about it.

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    You should use the InvariantCulture when persisting data that is culture dependent. See https://msdn.microsoft.com/library/system.globalization.cultureinfo.invariantculture(v=vs.100).aspx

    Leave the user's settings alone. They will not like you if you force them to use a different culture in your app.

  • Henrique.7684Henrique.7684 USMember ✭✭

    InvariantCulture isn't working properly for me... I try to save a decimal number dot as decimal and it gives out -Infinity.

    I can parse a number 0.001 to a double like: double.TryParse(txt_MinRate.Text, out double i))

    and when I try to save to another double this: double x = i / 100; or x= i / 100.0;

    The result is always
    x = -Infinity

    Anyone know why this is happening?

Sign In or Register to comment.