Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you get culture info string in javascript just like in .NET? [duplicate]

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" ?

like image 921
Tomasz Sikora Avatar asked Dec 11 '13 13:12

Tomasz Sikora


People also ask

When to use CultureInfo invariantculture?

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.

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 in c#?

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.


1 Answers

try this

<script>
var cultureInfo = '@System.Globalization.CultureInfo.CurrentCulture.Name';
</script>
like image 76
DaImTo Avatar answered Sep 20 '22 18:09

DaImTo