ASP.net没有使用其他区域设置资源文件 [英] ASP.net is not using other locale resource files

查看:83
本文介绍了ASP.net没有使用其他区域设置资源文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Default.aspx文件,我在其中获取本地化的值:

i have a Default.aspx file where i fetch localized values:

Default.aspx :

<asp:Localize meta:resourcekey="lblTitle" runat="server">Welcome</asp:Localize>

i然后创建一个匹配的 fallback 资源文件:

i then create a matching fallback resource file:

Default.aspx.resx :

lblTitle.Text    Welcome to Stackoverflow Localized

那行得通

现在,我想创建一个法国本地化版本:

Now i want to create, for example, a French localization:

Default.aspx.fr.resx :

lblTitle.Text    Bienvenue Stackoverflow

然后我将浏览器更改为发送法语语言环境:

And i change my browser to send a french language locale:

(它的作用):

GET http://stackoverflow.com/ HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */*
Accept-Language: fr-CH,qps-ploc;q=0.5
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Host: stackoverflow.com

除了它根本不起作用:

我正在遵循微软说的话:

例如,如果在App_LocalResources文件夹中有一个名为Default.aspx的页面,则可以创建以下文件:

For example, if you have a page named Default.aspx in the App_LocalResources folder, you might create the following files:

  • Default.aspx.resx.如果找不到与之匹配的语言,则这是默认的本地资源文件(后备资源文件).

  • Default.aspx.resx. This is the default local resource file (the fallback resource file) if no language match is found.

Default.aspx.es.resx.这是西班牙语的资源文件,没有文化信息.

Default.aspx.es.resx. This is the resource file for Spanish, without culture information.

Default.aspx.es-mx.resx.这是专门用于西班牙语(墨西哥)的资源文件.

Default.aspx.es-mx.resx. This is the resource file for Spanish (Mexico) specifically.

Default.aspx.fr.resx.这是法语的资源文件,没有文化信息.

Default.aspx.fr.resx. This is the resource file for French, without culture information.

.NET为什么不执行.NET应该做什么?

Why is .NET doing not what .NET should be doing?

更新:

从MSDN:

选择不同语言的资源文件

ASP.NET可以将页面的UICulture和Culture属性设置为浏览器传递的语言和文化值. ...有关详细信息,请参见如何:设置ASP的区域性和UI文化.NET网页全球化.

如何获取ASP.NET来将页面的UICultureCulture属性设置为浏览器传递的语言和区域性值?

How can i get ASP.NET to set the UICulture and Culture properties for the page to the language and culture values that are passed by the browser?

来自 如何:设置ASP的区域性和UI文化. NET网页全球化:

From How to: Set the Culture and UI Culture for ASP.NET Web Page Globalization:

用户可以在其浏览器中设置UI文化和文化.为了 例如,在Microsoft Internet Explorer的工具"菜单上,用户可以 单击"Internet选项",在常规"选项卡上,单击语言",然后 设置他们的语言偏好.如果enableClientBasedCulture Web.config文件中的全球化元素的属性已设置 确实,ASP.NET可以为网页设置UI文化和文化 自动,基于浏览器发送的值.

Users can set the UI culture and culture in their browsers. For example, in Microsoft Internet Explorer, on the Tools menu, users can click Internet Options, on the General tab, click Language, and then set their language preference. If the enableClientBasedCulture attribute of the globalization element in the Web.config file is set to true, ASP.NET can set the UI culture and culture for a Web page automatically, based on the values that are sent by a browser.

要以声明方式设置ASP.NET网页的区域性和UI文化

  • 要使ASP.NET将UI文化和文化设置为当前浏览器设置中指定的第一种语言,请将UICulture和文化设置为自动.或者,您可以将此值设置为auto: culture_info_name ,其中 culture_info_name 是区域性名称.有关区域性名称的列表,请参见 CultureInfo .您可以在 @ Page 指令或Web.config中进行此设置.文件.
  • To have ASP.NET set the UI culture and culture to the first language that is specified in the current browser settings, set UICulture and Culture to auto. Alternatively, you can set this value to auto:culture_info_name, where culture_info_name is a culture name. For a list of culture names, see CultureInfo. You can make this setting either in the @ Page directive or Web.config file.

推荐答案

尝试在.aspx文件的@ Page指令中设置UICulture="auto"Culture="auto".

Try setting UICulture="auto" and Culture="auto" in the @ Page directive in your .aspx file.

如何:设置ASP.NET的区域性和UI文化网页全球化

或者,您可以在web.config中完成相同的操作,除了它适用于每个页面:

Or, you can accomplish the same thing in the web.config, except it would apply to every page:

<system.web>
    <globalization uiCulture="auto" culture="auto" />
</system.web>

这篇关于ASP.net没有使用其他区域设置资源文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆