Introduction
in asp.net, starting from version 2.0, for each application we have two ways of storing resources for globalization of applications :
1. Global Resources folder :
in this folder, we store application wide localization elements. For example, localization of error and confirmation messages. localization of html text.
2. Local Resources folder :
this folder stores page and user control specific resource files, which store language specific property values, inlcuding text, ui properties, images and more.
3. Finally, as one requirements in some applications and websites, changing the culture dynamically by clicking on an image button. For this effect, on of the solutions, is to override the page function InitializeCulture(), then we use the session object, to store this preference.
This "InitializeCultre()" technique, is suitable for applications which require no profile based localization.
following will be some screen shots of the folder structure, and some code. Attached to this article, is the visual studio website, containing complete code.
For The global resources folder, here's how we create it :
right click on the project, and select add asp.net folder, then App_AppGlobalResources :
this will add the folder, with add an empby App_GlobalResources folder  next we add a resource file (.resex extension) to this folder The global resource files are accessbile to all objects application wide.
For The local resources folder, here's how to create it :
Local resources are file specific, and can be either created, or generated. They must be in the root of the folder containing the file as follows : as you may notice in the images, we have, to App_LocalResources Folder, one is for the root folder (especially for Default.aspx), and the other is for the controls folder (specifically for PersonnalInformation.ascx)
Here's how to generate a resource file for an ascx or aspx file (in this case, we'll do it for the DataEntryControls Folder) :
1. open the SimpleTextBox.ascx in design mode 2. Select Tools >> Generate Local Resource 3. the folder and it's corresonding file will be generated under the DataEntryControls Folder What's particular about the file generated is that it's generated with main properties already in created for you in the file, ready to be filled.
Here's what it looks like in Design View : Finally on resource files, they are very easily editable from xml code. all you do is :
right-click on the file >> Open With >> XML Editor : This is what the file looks like Scroll down to the bottom, until you reach the beginning for " that's where you can add, delete or edit resource elements for the file
This might be useful for those who wish to generate the support for resources from database or so. That will do it for global and local resource files. ConclusionIn an asp.net project, It is really better to differentiate the use of local and global resources. One bad practice, is to use global resources for all reource for both file specific resources and application specific resources. this can lead to huge, unmanageable resex files for each language.
In part 2, we will look at resources files in more detail, looking at the code to access these files, as well as how we can store resources about images, and what are the best practices for those kind of file types. Sample Project SourceDownload source files -19 kb |