dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
725 stars 1.56k forks source link

Android App .net 8.0-wrong Culture #10542

Closed ariktoledano closed 1 week ago

ariktoledano commented 3 weeks ago

Type of issue

Typo

Description

Hi After migrating from Xamarin.Android to Xamarin.AndroidX and .net 8 Android App - my current Culture of the app start as hebrew (he-IL) and I would expect it start as english(es-US) - it there a way to set the application and all of its component and sub thread to have english culture - I tried manually seeting it like that and it worked: CultureInfo ci = new CultureInfo("es-US"); //he-IL

Thread.CurrentThread.CurrentCulture = ci; Thread.CurrentThread.CurrentUICulture = ci; Console.WriteLine(CultureInfo.CurrentCulture); But the solution of setting culture for each thread doesn't make sense as we may miss places - I'd expect to have 1 place to configre it - maybe the android manifest.xml

-- just to clarify the reason to not have hebrew culture is that in my sqlite statement it disript the sql query by adding LTR mark near the minus see: //Select * from UserParentCompany where UserParentCompanyId in (0,999999,-400,-500,-600) [Enter feedback here]

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.currentculture?view=net-8.0#system-globalization-cultureinfo-currentculture

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Globalization/CultureInfo.xml

Document Version Independent Id

9ec3ac32-0cbd-b723-26c8-f3986f1c658c

Article author

@dotnet-bot

dotnet-policy-service[bot] commented 3 weeks ago

Tagging subscribers to this area: @dotnet/area-system-globalization

tarekgh commented 3 weeks ago

CC @vitek-karas @mkhamoyan

vitek-karas commented 2 weeks ago

@matouskozak

matouskozak commented 2 weeks ago

@ariktoledano would setting DefaultThreadCurrentCulture https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.defaultthreadcurrentculture?view=net-8.0 work for your problem?

ariktoledano commented 2 weeks ago

Thank you for the help :) in the end those lines helped me:

public static void SetEnglishCulture() { try { CultureInfo ci = new CultureInfo("es-US"); //he-IL

      CultureInfo.DefaultThreadCurrentCulture = ci;
      CultureInfo.DefaultThreadCurrentUICulture = ci;

      Thread.CurrentThread.CurrentCulture = ci;
      Thread.CurrentThread.CurrentUICulture = ci;
      Console.WriteLine(CultureInfo.CurrentCulture);
  }
  catch (Exception ex)
  {

  }

}

it's being call on Application derived class -> OnCreate method see->

[Application] public class ApplicationEx : Application, IActivityLifecycleCallbacks { .. public override void OnCreate() { _SetEnglishCulture() base.OnCreate(); ..

gewarren commented 1 week ago

Closing as this seems to be resolved.