Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 999
Annie B Avatar asked Sep 27 '12 02:09

Annie B


People also ask

What is CultureInfo?

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.

What is CultureInfo CurrentCulture?

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.

What is CultureInfo InvariantCulture C#?

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.

What is default culture in C#?

In the . NET Framework 4 and previous versions, by default, the culture of all threads is set to the Windows system culture.


1 Answers

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.
like image 103
McGarnagle Avatar answered Oct 20 '22 12:10

McGarnagle