Get current language in CultureInfo

后端 未结 6 1187
说谎
说谎 2020-12-05 17:20

How to identify the operating system\'s language using CultureInfo? E.g. if the language in Windows is set to French, I need to identify French and load the

相关标签:
6条回答
  • 2020-12-05 17:21

    I think something like this would give you the current CultureInfo:

    CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
    

    Is that what you're looking for?

    0 讨论(0)
  • 2020-12-05 17:22

    This is what i used:

    var culture = System.Globalization.CultureInfo.CurrentCulture;
    

    and it's working :)

    0 讨论(0)
  • 2020-12-05 17:25

    Current system language is retrieved using :

      CultureInfo.InstalledUICulture
    

    "Gets the CultureInfo that represents the culture installed with the operating system."

    InstalledUICulture

    To set it as default language for thread use :

       System.Globalization.CultureInfo.DefaultThreadCurrentCulture=CultureInfo.InstalledUICulture;
    
    0 讨论(0)
  • 2020-12-05 17:33

    To get the 2 chars ISO 639-1 language identifier use:

    System.Threading.Thread.CurrentThread.CurrentCulture.TwoLetterISOLanguageName;
    
    0 讨论(0)
  • 2020-12-05 17:46

    I tried {CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;} but it didn`t work for me, since my UI culture was different from my number/currency culture. So I suggest you to use:

    CultureInfo currentCulture = Thread.CurrentThread.CurrentUICulture;
    

    This will give you the culture your UI is (texts on windows, message boxes, etc).

    0 讨论(0)
  • 2020-12-05 17:46
    Windows.System.UserProfile.GlobalizationPreferences.Languages[0]
    

    This is the correct way to obtain the currently set system language. System language setting is completely different than culture setting from which you all want to get the language.

    For example: User may use "en-GB" language along with "en-US" culture at the same time. Using CurrentCulture and other cultures you will get "en-US", hope you get the difference (that may be innoticable with GB-US, but with other languages?)

    0 讨论(0)
提交回复
热议问题