I need to get culture string from browser's language.
I thought about getting it from javascript like this:
var userLang = navigator.language || navigator.userLanguage;
but it gives me only first part of culture info that i would get from .NET:
Thread.CurrentThread.CurrentCulture.Name;
So javascript gives me "de" or "pl" instead of "de-DE" or "pl-PL" like in .NET. Is there a way to get the "full info" ?
You can use the invariant culture for culture-sensitive string operations that are not affected by the conventions of the current culture and that are consistent across cultures.
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 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.
try this
<script>
var cultureInfo = '@System.Globalization.CultureInfo.CurrentCulture.Name';
</script>
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