Is it possible to get CultureInfo
by culture English name?
Imagine we have got: Danish, English, Spanish and etc...
Thank you!
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 invariant culture is culture-insensitive; it is associated with the English language but not with any country/region. You specify the invariant culture by name by using an empty string ("") in the call to a CultureInfo instantiation method. CultureInfo.
In an ASP.NET Web page, you can set to two culture values, the Culture and UICulture properties. The Culture value determines the results of culture-dependent functions, such as the date, number, and currency formatting, and so on. The UICulture value determines which resources are loaded for the page.
C# current cultureDefaultThreadCurrentCulture property gets or sets the default culture for threads in the current application domain. using System. Globalization; double val = 1235.56; Console. WriteLine($"Current culture: {CultureInfo.CurrentCulture.Name}"); Console.
var names = CultureInfo.GetCultures(CultureTypes.AllCultures).ToLookup(x => x.EnglishName);
names["English"].FirstOrDefault();
var EnglishCulture = CultureInfo.GetCultures(CultureTypes.AllCultures)
.Where(r => r.EnglishName == "English");
Or if you need FirstOrDefault
var EnglishCulture = CultureInfo.GetCultures(CultureTypes.AllCultures)
.FirstOrDefault(r=> r.EnglishName == "English");
There's no builtin method to get a culture by it's english name, so you could write one:
public static CultureInfo getCultureByEnglishName(String englishName)
{
// create an array of CultureInfo to hold all the cultures found,
// these include the users local culture, and all the
// cultures installed with the .Net Framework
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
// get culture by it's english name
var culture = cultures.FirstOrDefault(c =>
c.EnglishName.Equals(englishName, StringComparison.InvariantCultureIgnoreCase));
return culture;
}
Here's a demo: http://ideone.com/KX4U8l
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