如何在 ASP.NET、MVC、Razor、javascript 和 dhtmlx 中启用全球化和本地化?我一直在寻找答案,我发现的所有参考资料都使用了 jquery 的 Globalization.js 库。有人有使用 dhtmlx 或纯 javascript 的示例代码吗?我知道如何使用 @using Resources 引用 .cshtml 文件 (Razor) 中的资源,但是如何在嵌入 cshtml 的 javascripts 中引用这些资源,例如 @Resources.UserID?我说的是 ~/Scripts/Global.js 之类的脚本。
当我将它放在 system.web 下的 web.config 中时,创建一个 resources.de.resx 文件并将 de-DE 添加到 IE 中的语言中,标题使用下面的代码按预期更改,我的问题是在 javascripts 中引用它,所以我可以更改表格上的文字等。
<globalization culture="auto" uiCulture="auto" enableClientBasedCulture="true"/>
登录.cshtml:
@using SquishIt.Framework
@using SquishIt.Mvc
@using Resources
@{
Layout = null;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1DTD/xhtml1-strict.dtd">
<html>
<head>
<title>@Resources.Title</title>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<link rel="shortcut icon" type="image/x-icon" href="@Url.Content("~/Content/favicon.ico")" />
@(Bundle.Css()
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/dhtmlxlayout.css")
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/skins/dhtmlxlayout_dhx_skyblue.css")
.Add("~/Scripts/dhtmlx/dhtmlxWindows/codebase/dhtmlxwindows.css")
.Add("~/Scripts/dhtmlx/dhtmlxWindows/codebase/skins/dhtmlxwindows_dhx_skyblue.css")
.Add("~/Scripts/dhtmlx/dhtmlxForm/codebase/skins/dhtmlxform_dhx_skyblue.css")
.Add("~/Scripts/dhtmlx/dhtmlxForm/codebase/skins/dhtmlxform_dhx_skyblue_custom.css")
.Add("~/Content/Site.css")
.MvcRender("~/Content/SquishIt/BaseLogon_#.css"))
</head>
<body oncontextmenu="return false;">
<!-- Empty on purpose, JavaScript populates HTML -->
<!-- Text ruler used to measure text from JavaScript -->
<span id="TextRuler" class="TextRuler"></span>
</body>
<script language="javascript" type="text/javascript">
var SKIN_NAME = "dhx_skyblue";
var URL_WINDOWS_IMAGES = "@Url.Content("~/Scripts/dhtmlx/dhtmlxWindows/codebase/imgs/")";
var URL_LOGIN_FORM = "@Url.Content("~/XML/Forms/Base/Logon.xml")";
var URL_LOGIN = "@Url.Content("~/Base/Login/")";
var URL_MAIN = "@Url.Content("~/Base/Main/")";
var LOGON_SESSION_ID = "@(Session["LOGON_SESSION_ID"])";
var LOGOFF_MESSAGE = "@(ViewData.ContainsKey("LogOffMessage") ? ViewData["LogOffMessage"] : "")";
</script>
@(Bundle.JavaScript()
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/dhtmlxcommon.js")
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/dhtmlxlayout.js")
.Add("~/Scripts/dhtmlx/dhtmlxLayout/codebase/dhtmlxcontainer.js")
.Add("~/Scripts/dhtmlx/dhtmlxWindows/codebase/dhtmlxwindows.js")
.Add("~/Scripts/dhtmlx/dhtmlxForm/codebase/dhtmlxform.js")
.Add("~/Scripts/Global.js")
.Add("~/Scripts/Utility/Browser.js")
.Add("~/Scripts/Utility/XML.js")
.Add("~/Scripts/Utility/ErrorHandler.js")
.Add("~/Scripts/Utility/Form.js")
.Add("~/Scripts/Utility/MessageBox.js")
.Add("~/Scripts/Base/Logon.js")
.MvcRender("~/Content/SquishIt/BaseLogon_#.js"))
</html>