在 asp.net 网络表单中将区域性设置为 ar-AE 时,7 月的月份显示错误

Wrong month shows for July when culture is set to ar-AE in asp.net webform

网站在阿拉伯语中显示 july 的月份错误,这是在 asp.net webform 中开发的阿拉伯语网站,文化已正确设置为 'ar-AE ' 和事件日期在本地机器上显示正确的月份,但在产品上它显示属于 Egyptian culture

的月份

数据库中的日期存储为 smalldatetime 这种格式 2017-07-25 00:00:00

7 月错误

本地主机上的正确月份:25 يوليو 2017

生产月份错误:25 يوليه 2017

<asp:Label  ID="lblDate"  runat="server"  Text='<%# FormatDate(Eval("PublishDate")) %>'>
</asp:Label>

protected string FormatDate(object dt) {
  string date = String.Format("{0:MMMM dd, yyyy}", dt);
  date = String.Format("{0:dd MMMM yyyy}", dt);
  // Response.Write(date + "<br/>");
  return date;
}

文化已正确设置为阿联酋

protected override void InitializeCulture() {
  String lang = "ar-AE";
  CultureInfo ci = System.Threading.Thread.CurrentThread.CurrentUICulture;
  // Call function to detect Language and assign  to session variable
  Thread.CurrentThread.CurrentCulture = new CultureInfo(lang);
  Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);

  base.InitializeCulture();
}

可能是什么原因,会不会是生产服务器本身?

我们检查了几乎所有的可能性并尝试了所有方法,只是错误的月份为 7 月休息一切正常。

我还交叉检查了生产服务器的语言设置、IIS 设置,一切似乎都没问题,我唯一能指出的是服务器有所有最新更新,可能是我们遗漏了什么。我们在不同的 windows 7 台机器上测试了它工作正常。

更新:我也尝试了建议的解决方案,但它一直显示错误的月份 يوليه。这是错误的。我们也对其进行了测试,它在服务器上显示了正确的区域性。

Fiddle 例子也显示错误的月份 https://dotnetfiddle.net/ZAOJ7H

我尝试使用以下代码行查找本地化的 DateTime 月份名称:

DateTime dt = DateTime.Parse("2017-07-25 00:00:00");

string arabicMonth = new CultureInfo("ar-AE").DateTimeFormat.GetMonthName(dt.Month);

结果代码给出 يوليه 而不是 يوليو,表明 Windows 阿拉伯语公历月份名称的本地化出了点问题。

通过一点点了解,它是由位于 %WINDIR%\System32\locale.nlslocale.nls 文件引起的,其中包含不正确的数据,其中 7 月份在当前系统以外的其他阿拉伯语版本中显示文化使用.

由于 NLS 文件是二进制格式,即使在十六进制编辑器中查看它也很难读取和编辑存储的区域设置信息。据我所知,这个问题已经被微软在 KB981981 更新 Windows 7 和 Server 2008 R2 系统中修复,您可以根据使用的平台执行更新(之后需要重启):

Update for Windows 7 32-bit (KB981981) - 5/24/2010

Update for Windows 7 64-bit (KB981981) - 5/24/2010

注意:确保所有受影响的机器都安装了此更新以获得最佳结果。如果由于某些限制而无法安装更新,我建议尝试使用 datepicker 的 jQuery 插件作为解决方法,该插件显示 7 月份的 يوليو

PS:我还在 OP 的 fiddle -

中尝试了 zahed 的解决方案
DateTime.Parse("2017-07-25 00:00:00").ToString("dd dddd , MMMM, yyyy", new CultureInfo("ar-AE"))

但它也显示 25 الثلاثاء , يوليه, 2017(即 يوليه),因此这不是字符串格式问题,而是如上所述的 Windows 本地化问题。

参考文献:

Description of Software Update Services and Windows Server Update Services changes in content for 2010

How to convert the month name in english text in datetime to arabic text using C#?

相关:

Michael S. Kaplan - Arabic locales for month names

设计代码:

<div>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>
</div>

C# 背后的代码:

protected void LinkButton1_Click(object sender, EventArgs e)
{
    Label1.Text = DateTime.Parse("2017-07-25 00:00:00").ToString("dd dddd , MMMM, yyyy", new CultureInfo("ar-AE"));
}

更新的答案:

我可以想象 OS 支持的所有语言(考虑到这是信息的来源)。

这是一个列表:default supported languages by OS