错误的月份显示7月份,在asp.net webform中将文化设置为ar-AE

时间:2017-10-11 08:58:49

标签: c# asp.net date webforms uiculture

网站显示阿拉伯语中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机器上测试过它只是工作正常。

更新:我也尝试过解决方案建议,但它一直显示JULY يوليه错误的月份。这是错的。我们测试了它,它也显示了服务器上的正确文化。

小提琴示例也显示错误的月https://dotnetfiddle.net/ZAOJ7H

2 个答案:

答案 0 :(得分:2)

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

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

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

结果代码提供了يوليه而不是يوليو,表示在使用阿拉伯语进行格里高利月名称的Windows本地化时出现了问题。

通过查找一点,它是由位于locale.nls的{​​{1}}文件导致的,其中包含不正确的数据,其中 7月份显示在其他阿拉伯语版本中,而不是使用当前系统文化

由于NLS文件是以二进制格式化的,因此即使在十六进制编辑器中查看,也很难读取和编辑存储的语言环境信息。 AFAIK,此问题已由Microsoft针对Windows 7&amp ;;的 KB981981 更新修复。在Server 2008 R2系统中,您可以根据使用的平台执行更新(之后需要重新启动):

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

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

注意:确保使用此更新安装的所有受影响的计算机都能获得最佳结果。如果由于某些限制而无法安装更新,我建议您尝试使用%WINDIR%\System32\locale.nls的jQuery插件,该插件会在7月份显示datepicker作为解决方法。

PS:我也尝试过OP的小提琴 -

يوليو

但它也显示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

答案 1 :(得分:0)

设计代码:

<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"));
}

更新回答:

我会想象操作系统支持的所有语言(考虑到信息的来源)。

以下是一个列表:default supported languages by OS