【问题标题】:ASP.NET AJAX is not rendering a __cultureInfo JS object for en-US localesASP.NET AJAX 不为 en-US 语言环境呈现 __cultureInfo JS 对象
【发布时间】:2012-06-03 22:59:04
【问题描述】:

我在我的网站上使用 ASP.NET AJAX 控件,并在 ScriptManager 上启用了以下设置:

scriptManager.EnableScriptGlobalization = true;
scriptManager.EnableScriptLocalization = true;

当我将浏览器语言切换为法语时,我会在页面上呈现一个名为 __cultureInfo 的丰富 JavaScript 对象,其中包含初始化日期选择器和正确格式化所需的所有好东西日期字符串。

但是,当区域设置为美国英语时,不会呈现 __cultureInfo 对象。

有没有办法强制 ASP.NET AJAX 为 all 语言环境呈现这个 JavaScript 变量/对象?我想初始化所有支持区域设置的控件,而不必使用特殊的美国英语。

【问题讨论】:

  • 好吧,当我在等待一个明确的答案时,我已经开始为“en-US”中缺少的成员制作包装器:locale.getFirstDayOfWeek(), locale.getName( ) 和 locale.getLongDatePattern()。我正在检查是否“typeof(__cultureInfo) === 'undefined'”。如果是这样,那么我返回英语的硬编码值。这可行,但确实很笨拙。
  • 我今天也遇到了这个问题,花了我几个小时:“ClientCultureInfo.GetClientCultureScriptBlock(CultureInfocultureInfo)”有以下代码片段:Type type = (cultureInfo.DateTimeFormat == null) ? null : cultureInfo.DateTimeFormat.Calendar.GetType(); if (cultureInfo.Equals(enUS) && (type == typeof(GregorianCalendar))) { return null; }如果当前线程的文化是“en-US” ,似乎ScriptManager不会呈现“var __cultureInfo =”,我不确定MS为什么这样做。

标签: asp.net ajax localization cultureinfo scriptmanager


【解决方案1】:

Microsoft 将 Invarient 文化克隆到 en-US,因此即使未加载 __cultureInfo,您也应该在 Sys.CultureInfo.CurrentCulture

中拥有所需的一切
switch(typeof(cultureInfo)) {
case "string":
    // this is true when the server is 3.5
    cultureInfo = window.eval("(" + cultureInfo + ")");
    // allow fallthrough to object
case "object":
    this.CurrentCulture = this._parse(cultureInfo);
    delete __cultureInfo;
    break;
default:
    cultureInfo = clone(invariant);
    // fix up the differences
    cultureInfo.name = "en-US";
    cultureInfo.numberFormat.CurrencySymbol = "$";
    var dtf = cultureInfo.dateTimeFormat;
    dtf.FullDatePattern = "dddd, MMMM dd, yyyy h:mm:ss tt";
    dtf.LongDatePattern = "dddd, MMMM dd, yyyy";
    dtf.LongTimePattern = "h:mm:ss tt";
    dtf.ShortDatePattern = "M/d/yyyy";
    dtf.ShortTimePattern = "h:mm tt";
    dtf.YearMonthPattern = "MMMM, yyyy";
    this.CurrentCulture = this._parse(cultureInfo);
    break;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-03
    • 2020-04-18
    • 2021-01-27
    • 2011-06-05
    • 2019-09-21
    • 1970-01-01
    • 2018-07-12
    • 1970-01-01
    相关资源
    最近更新 更多