简体   繁体   English

ASP.NET客户端本地化和Javascript

[英]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.

相关问题 客户端JavaScript中的ASP.NET验证程序错误消息 - ASP.NET validators error message in client-side JavaScript Javascript客户端验证不起作用ASP.Net - Javascript client-side validation does not work ASP.Net javascript客户端向asp.net服务器端返回值 - javascript client-side return value to asp.net server-side 在服务器端ASP.Net上访问客户端阵列 - Accessing Client-Side arrays on Server Side ASP.Net ASP.net:传递动态创建的(通过客户端javascript)值以及回发 - ASP.net: pass dynamically created (by client-side javascript) value along with postback 如何从 JavaScript 触发 ASP.NET Core 客户端验证 - How to trigger ASP.NET Core client-side validation from JavaScript 仅当ASP.NET客户端验证成功时,才使用Javascript Click处理程序 - Javascript Click handler only if ASP.NET client-side validation succeeds 在ASP.NET中使用Messenger Connect客户端库时出现Javascript错误 - Javascript error when using Messenger Connect client-side library in ASP.NET 当文本框通过javascript更改客户端时,ASP.NET文本框在回发后丢失值 - ASP.NET textbox losing value after postback when value is changed client-side via javascript 在javascript中,我收到错误ASP.NET Ajax客户端框架无法加载 - In javascript I get error ASP.NET Ajax client-side framework failed to load
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM