How do you go about enabling Globalization and Localization in ASP.NET, MVC, Razor, javascript and dhtmlx? I have been looking around for answers and all references I found used the Globalization.js library from jquery. Does anybody have example code using dhtmlx or pure javascript instead? I know how to reference resources within the .cshtml files (Razor) with @using Resources, but how do you reference these resources, like @Resources.UserID, within javascripts embeded within cshtml? I am talking about scripts like ~/Scripts/Global.js.
When I put this in web.config under system.web, create a resources.de.resx file and add de-DE to languages in IE, the title changes as expected using below code, my problem is referencing this in javascripts, so I can change text on forms etc.
<globalization culture="auto" uiCulture="auto" enableClientBasedCulture="true"/>
login.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>