Localization in ASP.NET 1.1

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

Localization in ASP.NET 1.1

Localization in ASP.NET 1.1 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'));

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航