Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CultureInfo in JavaScript

Tags:

javascript

In c# I use the below method in order to get the CultureInfo.

System.Globalization.CultureInfo.CurrentCulture.Name // output :en-US

Can any one tell me how can I get the CultureInfo in JavaScript?

like image 848
sharmila Avatar asked Jan 18 '13 06:01

sharmila


2 Answers

This is a very old post an is definately in need of an update. All major browsers now support the navigator property. Simply use

var lang = navigator.language
like image 171
JSON Avatar answered Nov 03 '22 05:11

JSON


Very easy way is to render it into the view, like this:

<script>
  var cultureInfo = '@System.Globalization.CultureInfo.CurrentCulture.Name';
</script>

This is razor syntax, if you use classic asp.net, then use:

<script>
  var cultureInfo = '<%= System.Globalization.CultureInfo.CurrentCulture.Name %>';
</script>
like image 38
SharpNoiZy Avatar answered Nov 03 '22 04:11

SharpNoiZy