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.
The CultureInfo class provides culture-specific information, such as the language, sublanguage, country/region, calendar, and conventions associated with a particular culture. This class also provides access to culture-specific instances of the DateTimeFormatInfo, NumberFormatInfo, CompareInfo, and TextInfo objects.
The CultureInfo. CurrentCulture property is a per-thread setting; that is, each thread can have its own culture. You get the culture of the current thread by retrieving the value of the CultureInfo. CurrentCulture property, as the following example illustrates. C# Copy.
The CultureInfo. InvariantCulture property is used if you are formatting or parsing a string that should be parseable by a piece of software independent of the user's local settings. The default value is CultureInfo. InstalledUICulture so the default CultureInfo is depending on the executing OS's settings.
In the . NET Framework 4 and previous versions, by default, the culture of all threads is set to the Windows system culture.
Yes, there is, GetCultures:
System.Globalization.CultureInfo.GetCultures(System.Globalization.CultureTypes.SpecificCultures)
That returns an array of CultureInfo
objects, so if you want the string names you could use something like:
IEnumerable<CultureInfo> cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); string[] names = cultures.Select(c => c.Name).ToArray();
Note the "Culture Types" enum (from the MSDN link). I suppose the most useful ones would be NeutralCultures and SpecificCultures.
- NeutralCultures Cultures that are associated with a language but are not specific to a country/region. The names of .NET Framework cultures consist of the lowercase two-letter code derived from ISO 639-1. For example: "en" (English) is a neutral culture. Custom cultures can have any user-specified name, not just a two-letter code. The invariant culture is included in the array of cultures returned by the CultureInfo.GetCultures method that specifies this value.
- SpecificCultures Cultures that are specific to a country/region. The names of these cultures follow RFC 4646 (Windows Vista and later). The format is "-", where is a lowercase two-letter code derived from ISO 639-1 and is an uppercase two-letter code derived from ISO 3166. For example, "en-US" for English (United States) is a specific culture. Custom cultures can have any user-specified name, not just a standard-compliant name.
- InstalledWin32Cultures All cultures that are installed in the Windows operating system. Note that not all cultures supported by the .NET Framework are installed in the operating system.
- AllCultures All cultures that ship with the .NET Framework, including neutral and specific cultures, cultures installed in the Windows operating system, and custom cultures created by the user.
- UserCustomCulture Custom cultures created by the user.
- ReplacementCultures Custom cultures created by the user that replace cultures shipped with the .NET Framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With