locked
How to get the current OS culture RRS feed

  • Question

  • User470120106 posted

    Hi guys, hopefully a fairly simple one. Apologies if this has been asked before, but I couldn't find an existing thread for this.

    Does anyone know how you get the current Windows OS culture from within an ASP.NET application (C#)? This would be related to the regional settings you configure in Windows Control Panel.

    Thanks,
    Dan.

    Wednesday, September 18, 2013 8:40 AM

Answers

  • User-718146471 posted

    This might be what you are looking for: http://social.msdn.microsoft.com/Forums/vstudio/en-US/080649c6-6cc1-4230-91d9-ea681777051d/is-it-possible-to-find-os-installed-language-by-c

     

     

    You can iterate this way
    
    
    
    foreach (InputLanguage c in InputLanguage.InstalledInputLanguages)
    
    MessageBox.Show(c.Culture.EnglishName);
    
    And 
    
    InputLanguage.CurrentInputLanguage can be used to get or set input language
     
    --------------------------------------------------------------------------------
    Arjun Paudel

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 18, 2013 8:44 AM
  • User-1716253493 posted
    To check your app culture/uiculture use : Label1.Text = culture;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 18, 2013 9:50 AM
  • User470120106 posted

    ^^ Not sure I understand this, but thanks anyway.

    Surprisingly it doesn't look like there's a 'clean' way of doing what I want, so I ended up having to use the following:

    [DllImport("Kernel32.dll")]
    private static extern int GetUserDefaultLCID();

    This calls the GetUserDefaultLCID function of the Win32 API, which looks to be getting the locale ID related to the drop-down list selection in the "Formats" tab of the Region and Language dialogue. (I think might be user specific, but that's OK for my purposes as it will just pick up the locale ID of the user who the app pool is running under).

    Apparently it's this function which .NET calls behind the scenes the first time you access Thread.CurrentThread.CurrentCulture unless you've set the thread culture explicitly or via config.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 18, 2013 11:44 AM

All replies

  • User-718146471 posted

    This might be what you are looking for: http://social.msdn.microsoft.com/Forums/vstudio/en-US/080649c6-6cc1-4230-91d9-ea681777051d/is-it-possible-to-find-os-installed-language-by-c

     

     

    You can iterate this way
    
    
    
    foreach (InputLanguage c in InputLanguage.InstalledInputLanguages)
    
    MessageBox.Show(c.Culture.EnglishName);
    
    And 
    
    InputLanguage.CurrentInputLanguage can be used to get or set input language
     
    --------------------------------------------------------------------------------
    Arjun Paudel

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 18, 2013 8:44 AM
  • User470120106 posted

    Thanks, that's the best way I've seen suggested yet. I've done some experimentation, and this looks to be returning the input language configured from within the "Keyboards and Languages" tab of the Region and Language dialogue in Windows 7. Ideally, I would prefer a way of getting at either the "Current Location" configured within the "Location" tab, or the System Locale configured within the "Administrative" tab.

    Wednesday, September 18, 2013 8:59 AM
  • User-1716253493 posted
    To check your app culture/uiculture use : Label1.Text = culture;
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 18, 2013 9:50 AM
  • User470120106 posted

    ^^ Not sure I understand this, but thanks anyway.

    Surprisingly it doesn't look like there's a 'clean' way of doing what I want, so I ended up having to use the following:

    [DllImport("Kernel32.dll")]
    private static extern int GetUserDefaultLCID();

    This calls the GetUserDefaultLCID function of the Win32 API, which looks to be getting the locale ID related to the drop-down list selection in the "Formats" tab of the Region and Language dialogue. (I think might be user specific, but that's OK for my purposes as it will just pick up the locale ID of the user who the app pool is running under).

    Apparently it's this function which .NET calls behind the scenes the first time you access Thread.CurrentThread.CurrentCulture unless you've set the thread culture explicitly or via config.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 18, 2013 11:44 AM