【问题标题】:Issue with asp.net expression builderasp.net 表达式生成器的问题
【发布时间】:2015-10-16 00:15:39
【问题描述】:

我有提到in this question 的相同问题,但接受的答案对我不起作用。基本上我只是想在 web 表单页面中添加对元素(例如按钮、标签)的翻译。

我也检查了其他网站,它们都指向相同的解决方案。例如。这个这个MSDN article 说:

例如,当自动本地化内容时,您可以使用表达式语法设置服务器控件的 Text 属性,如下例所示:

<asp:Label id="label1" runat="server" text="<%$ Resources: Messages, ThankYouLabel %>" />

在 App_GlobalResources 文件夹中,您可以拥有名为 Messages.resx、Messages.es.resx、Message.de.resx 等的资源文件 - 您想要支持的每种语言的 Messages 资源文件

在我的情况下,翻译没有被选中,我总是看到中性语言(英语)。

我也用几行代码做了一个虚拟骨架项目,App_GlobalResources 文件夹中有 2 个资源文件:

  • MyResources.resx
  • MyResources.nl.resx

Default.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("nl");
    Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("nl");
}

默认.aspx

<%-- this displays the translation (nl) --%>
<%= Resources.MyResource.MyKey %>
<%-- this displays the neutral language (en) --%>
<asp:Label ID="Label1" runat="server" Text="<%$ Resources: MyResource, MyKey %>" />

任何想法我想念什么?

【问题讨论】:

    标签: c# asp.net .net localization


    【解决方案1】:

    经过几次尝试(和失败)后,我得到了它的工作。这个answer 和这个MSDN page 让我走上了正轨。

    简而言之,我需要像这样覆盖InitializeCulture 方法:

    protected override void InitializeCulture()
    {
        UICulture = "nl";
        Culture = "nl"
        Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("nl");
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("nl");
        base.InitializeCulture();
    }
    

    为了使它成为一个通用的解决方案,我必须创建一个新的 PageBase 类,它被所有页面继承,因为它很好地描述了here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-17
      • 2014-03-23
      • 2018-06-21
      • 2022-11-14
      • 2010-10-08
      • 1970-01-01
      相关资源
      最近更新 更多