Search code examples
c#localizationresxculturecultureinfo

c# : In a dotnet class is there a property that states if the "Current" culture is actual the default culture?


Is there a property in some class that can tell me if the current culture is actually the default culture.

Similar to how localization works with winforms. It states in a form if the language is default.

lets say if i am in en-US - how can i tell via code if en.US is the actual default?

I need to implement some localization for some XML files which .net doesn't support hence i want to implement my own ...

And do it how winforms works i.e

nameofxml.default.xml (this is the default local)
nameofXml.de-de.xml (this is german) 

etc

does a property exist?


Solution

  • System.Globalization.CultureInfo.CurrentCulture indicates you system's Control Panel Region settings, while System.Globalization.CultureInfo.CurrentUICulture corresponds to the system's Input UI Language setting (which you can't change unless you have Multilingual User Interface installed).

    Therefore you can use the following code snippet to determine the 'default' culture:

    using System.Globalization;
    // N.B. execute the following line *before* you programmatically change the CurrentCulture
    // (if you ever do this, of course)
    
    // Gets the CultureInfo that represents the culture used by the current thread
    CultureInfo culture = CultureInfo.CurrentCulture;
    string code = culture.IetfLanguageTag; // e.g. "en-US", "de-DE", etc.
    

    Then you can use the code to locate your .xml files.