Localization in ASP.NET 1.1

本文介绍了在VS.NET中处理ASP.NET项目资源文件的方法。可直接添加.resx文件,VS.NET会自动编译成附属程序集;也能手动添加。还说明了如何查看项目中与每个Web表单关联的resx文件,以及创建资源管理器的代码示例,建议为Web应用创建单个资源管理器实例。

http://www.dotnet247.com/247reference/msgs/11/56463.aspx

Matt Hooper
Microsoft ASP.NET Developer Support

You can simply add assembly resource files (.resx files) to your project
and VS.NET will compile them into satellite assemblies automatically. For
example, if the following files are adding to a project called MyProject:

stuff.en-us.resx
stuff.es.resx
more_stuff.en-us.resx
more_stuff.es.resx

VS.NET will output two satellite assemblies (one per locale) into the
project directory:

/bin/en-us/MyProject.resources.dll
/bin/es/MyProject.resources.dll

To manually add a assembly resource file from VS.NET by right-clicking on
the project > Add New Item > Assembly Resource File.

Also, VS.NET automatically adds a resx file for each web form in the
project. That are automatically linked into the project's primary assembly.
You can see them by in the Solution Explorer window by the following steps:

1. Select the web application project.
2. Click the "Show All Files" button.
3. Expand one of the web form nodes that the project contains until a
.resx file is visible.

Try using this approach to create the resource manager:

ResourceManager resources = new ResourceManager(
"<WebProjectName>.<ResName>",
Assembly.GetExecutingAssembly(),
null );

...where the resx files are named:

<ResName>.<Culture>.resx

The code below would create the resource manager that could be used in the
"MyProject" example from my earlier post:

ResourceManager resources = new ResourceManager(
"MyProject.stuff",
Assembly.GetExecutingAssembly(),
null );

You may also want to consider creating a only a single instance of the
ResourceManager for your web app that is kept in a static class member or
the Application object. This cause the resources to be loaded only once
per application.

Response.Write(rm.GetString("Test1"));

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值