Xamarin -- getting user's Locale, or converting from CultureInfo.CurrentCulture to Xamarin.Essentials.Locale.

Mark Fairchild 1 Reputation point
2021-10-07T15:38:52.967+00:00

I'm doing some work with TTS in Xamarin, and I'm pretty new to this platform. I'd like to select a Locale for the TTS system based on the user's language settings, but CultureInfo doesn't seem to provide any convenient way to map to a Locale. Any tips?

Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JarvanZhang 23,971 Reputation points
    2021-10-08T06:11:04.22+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    To get the user's locale, try using CultureInfo.CurrentCulture property.

       var cultureName = CultureInfo.CurrentCulture.Name;  
    

    Here are the related docs, you could refer to:
    https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo.currentculture?view=net-5.0
    https://learn.microsoft.com/en-us/dotnet/api/system.globalization.cultureinfo?view=net-5.0#properties

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.