ASP.NET C#语言文件不起作用

时间:2021-07-28 01:42:04

I just started using explicit resource files. I performed these steps:

我刚开始使用显式资源文件。我执行了以下步骤:

  • In the root create the folder: App_GlobalResources
  • 在根目录中创建文件夹:App_GlobalResources

  • Add two resx files: LocalizedText.en-us.resx and LocalizedText.resx
  • 添加两个resx文件:LocalizedText.en-us.resx和LocalizedText.resx

  • In both files I have a value called 'InstitutionTitle'
  • 在这两个文件中,我有一个名为'InstitutionTitle'的值

  • In LocalizedText.en-us.resx the value is 'Institution' and in the LocalizedText.resx the value is 'Instelling'
  • 在LocalizedText.en-us.resx中,值为“Institution”,在LocalizedText.resx中,值为“Instelling”

  • In my .aspx file I have the following label:

    在我的.aspx文件中,我有以下标签:

    <asp:Label ID="lblInstitution" runat="server" Text="<%$ Resources:LocalizedText, InstitutionTitle %>" />

When I run this page, I always get the dutch version. Whether I set the language in my browser (FF and IE7) or not, I always get the dutch version. When I request the browsers' language I get en-us (using: Response.Write(Request.Headers["Accept-Language"]);).

当我运行这个页面时,我总是得到荷兰语版本。无论我是否在我的浏览器(FF和IE7)中设置语言,我总是得到荷兰语版本。当我请求浏览器的语言时,我得到了en-us(使用:Response.Write(Request.Headers [“Accept-Language”]);)。

What's the issue and how can I fix it?

问题是什么,我该如何解决?

2 个解决方案

#1


Setting the language preferences in the browser is not enough. You have to make sure that the current thread's Culture and UICulture properties are set accordingly in ASP.NET.

在浏览器中设置语言首选项是不够的。您必须确保在ASP.NET中相应地设置当前线程的Culture和UICulture属性。

You can do this either programmatically or declaratively on your page (Culture and UICulture attributes of the <%@Page %> directive).

您可以在页面上以编程方式或声明方式执行此操作(<%@ Page%>指令的Culture和UICulture属性)。

Or you can let ASP.NET set them automatically by setting the web.config entry shown below and setting the Culture/UICulture properties of the page/masterpage to "auto".

或者,您可以通过设置下面显示的web.config条目并将页面/母版页的Culture / UICulture属性设置为“auto”来让ASP.NET自动设置它们。

// web.config:
<globalization enableClientBasedCulture="true" ...>

// page/masterpage:
<%@ Page ... Culture="auto" UICulture="auto" %>

Check this page for details.

查看此页面了解详细信息。

#2


@martijn:

  1. check the browsers caching settings. Caching should be off all the time when developing.

    检查浏览器缓存设置。在开发时,缓存应该一直处于关闭状态。

  2. Install Firebug (FF) and Fiddler(IE) to see what's being transfered over the wire.

    安装Firebug(FF)和Fiddler(IE)以查看通过电线传输的内容。

Hope this helps...

希望这可以帮助...

signed,

A fellow countryman

同乡

#1


Setting the language preferences in the browser is not enough. You have to make sure that the current thread's Culture and UICulture properties are set accordingly in ASP.NET.

在浏览器中设置语言首选项是不够的。您必须确保在ASP.NET中相应地设置当前线程的Culture和UICulture属性。

You can do this either programmatically or declaratively on your page (Culture and UICulture attributes of the <%@Page %> directive).

您可以在页面上以编程方式或声明方式执行此操作(<%@ Page%>指令的Culture和UICulture属性)。

Or you can let ASP.NET set them automatically by setting the web.config entry shown below and setting the Culture/UICulture properties of the page/masterpage to "auto".

或者,您可以通过设置下面显示的web.config条目并将页面/母版页的Culture / UICulture属性设置为“auto”来让ASP.NET自动设置它们。

// web.config:
<globalization enableClientBasedCulture="true" ...>

// page/masterpage:
<%@ Page ... Culture="auto" UICulture="auto" %>

Check this page for details.

查看此页面了解详细信息。

#2


@martijn:

  1. check the browsers caching settings. Caching should be off all the time when developing.

    检查浏览器缓存设置。在开发时,缓存应该一直处于关闭状态。

  2. Install Firebug (FF) and Fiddler(IE) to see what's being transfered over the wire.

    安装Firebug(FF)和Fiddler(IE)以查看通过电线传输的内容。

Hope this helps...

希望这可以帮助...

signed,

A fellow countryman

同乡