开发者

Create Resource from asp.net page

开发者 https://www.devze.com 2023-01-09 09:26 出处:网络
is it better to create one resource for every asp.net page application. or to create a global resource for all pages?

is it better to create one resource for every asp.net page application. or to create a global resource for all pages? my application has about 100 pages and 200 usercontrols. if i want to create global resource can how can i use this Feature of visual studio that able us to generate resource file automati开发者_如何学Ccally from every page with this way :

From Microsoft :

1)Open the page for which you want to create a resource file.

2)Switch to Design View.

3)In the Tools menu, click Generate Local Resource.

thanks for attentions :) . Edition : Does Sharepoint has just one resource file?!


I see most applications split between the 2. The things that come back on most pages like Ok, Cancel, Address, Firstname, ... go in the global one. Specific terms go in the local resources.

In my former application however we deciced to not put it in resources but in the database. We made custom controls which had a translationkey property which mapped to a unique key in the database. The translations were put in the Cache object to keep it as close as possible in reach of the UI parts that needed it. It worked great for us and we needed less deployments since translations could be directly be enhanced in the production database when needed (luckily not that often).

Update due to comment:

public class TranslationLabel : Label, ITranslation
{
    public string TranslationKey { get; set; }
}

In a custom basePage class we looped over the controls collection and took out the ones that implemented the ITranslation interface. Then grab the TranslationKey and look it up in the dictionary retrieved from Cache.

Usage:

<cl:TranslationLabel runat="server" TranslationKey="WarningMessage" />


Use both global and local resource. Put common strings in the Global resource, and page related strings in the Local resource.

I suggest to:

  1. Generate local resource from the page
  2. Move common strings in the global resource

To create a global resource, click on the project, Add new item..., Resource File

0

精彩评论

暂无评论...
验证码 换一张
取 消