【发布时间】: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