[英]ASP.NET Client-side localization and Javascript
I am building a web-based application which supports French language. 我正在构建一个支持法语的基于Web的应用程序。 When in ASP.NET I set the Thread.CurrentThread.CurrentCulture to fr-FR.
在ASP.NET中,我将Thread.CurrentThread.CurrentCulture设置为fr-FR。 Everything work in ASP.NET in French format which is great.
一切都以法语格式在ASP.NET中运行,这很棒。 However if I have a code such as below, I run into incompatibility issues between ASP.NET and Javascript:
但是,如果我有如下代码,则会遇到ASP.NET与Javascript不兼容的问题:
var value = <%:Model.Amount%>;
var total = value * 12;
The above will be rendered as: 上面将呈现为:
var value = 1023,00;
var total = value * 12;
And get the following error message from the browser: 并从浏览器中获取以下错误消息:
Uncaught SyntaxError: Unexpected number 未捕获的语法错误:意外的数字
Is there anyway to tell the browser what locale to work with? 无论如何,有没有告诉浏览器使用哪种语言环境? I tried the "accept-language" meta tag and that did not help.
我尝试了“ accept-language”元标记,但没有帮助。
NOTE: I am not looking for finding out how I can render the decimal values into the screen without culture, well aware of: 注意:我不是要寻找如何在不使用文化的情况下将十进制值呈现到屏幕中的方法,请注意:
<%:Convert.ToString(Model.Amount, new System.Globalization.CultureInfo(""))%>
I am looking for a way to tell the browser what my locale is, so that I wouldn't have to go through all pages of the project and see where things are breaking and change them. 我正在寻找一种方法来告诉浏览器我的语言环境是什么,这样我就不必遍历项目的所有页面并查看问题所在并进行更改。
have you tried accounting.js http://josscrowcroft.github.io/accounting.js/ 您是否尝试过Accounting.js http://josscrowcroft.github.io/accounting.js/
accounting.js is a tiny JavaScript library for number, money and currency formatting, with optional excel-style column rendering (to line up symbols and decimals). accounting.js是一个小巧的JavaScript库,用于数字,货币和货币格式设置,具有可选的excel样式的列呈现(用于将符号和小数点对齐)。 It's lightweight, fully localisable and has zero dependencies.
它是轻量级的,完全可本地化的并且具有零依赖性。
or 要么
<%:Model.Amount.ToString("N2", CultureInfo.CreateSpecificCulture("en-US").Replace(",", "")%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.