Search code examples
c#.netglobalization

Constants for CultureInfo Name


Is there a set of constants or an enumeration in C# system/globalization namespace which contains valid culture names?

I am looking for something so that I don't have to type in "en-GB", etc.


Solution

  • No there isn't. The list of available cultures is system-specific - you can even register new custom cultures using CultureAndRegionInfoBuilder.

    So if you want this, you'll have to create your own enum or constants for the subset of common cultures that you're interested in, e.g.:

    public static class KnownCulture
    {
        public readonly String EnglishUS = "en-US";
        public readonly String EnglishGB = "en-GB";
        ... etc ...
    }
    

    or

    public enum KnownLCID
    {
        EnglishUS = 0x409,
        EnglishGB = 0x809,
        ...
    }
    

    This is analogous to the KnownColor enumeration: it's not possible to create an enumeration for all possible colors, but it can make sense to have an enumeration for frequently used ones.

    I wouldn't expect Microsoft to provide an equivalent KnownCulture enumeration out of the box, as it's rather sensitive (why is my culture not included?).