|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.|
How to: Create Resource Files for ASP.NET Web Sites
A resource file is an XML file that contains the strings that you want to translate into different languages. You create a separate resource file for each language that you want to translate a Web page into.
Global resource files are available to any page or component in the Web site. Local resource files are associated with a single Web page and contain the translated text for that page only. For more information, see.
Visual Studio 2005 includes an editor for managing resources that simplifies the process of creating resource files. For more information, see How to: Create Resource Files for ASP.NET Web Sites (Visual Studio) and How to: Create Resource Files for ASP.NET Web Sites and How to: Create Resource Files for ASP.NET Web Sites and How to: Create Resource Files for ASP.NET Web Sites.
To create a resource file for an ASP.NET Web site
Create a new text file that has the extension
In the text file, create key/value pairs using the format key
=value. Keys are not case sensitive.
The following code example shows two key/value pairs:
Save the file.
In Microsoft Windows, open a Command Prompt window, and then go to the folder that contains the command-line utilities for the .NET Framework version 2.0. The path is as follows:
For version, substitute the name of the folder for the .NET Framework version that you are currently using.
Run the Resgen utility, using the following syntax:
resgen textfile.txt resourcefile.resx
For example, if in step 1 you created a file named
SiteResources.txt, the command might look similar to the following:
resgen c:\WebSite\SiteResources.txt c:\WebSite\SiteResources.resx
You can include a full path, when specifying the names of the text and resource files.
When the command runs, it creates a .resx file that includes the correct XML definitions and elements.
Copy the resource file to the appropriate location in the Web site:
To use the resource file as a global resource, copy it to App_GlobalResources.
To use the resource file as a local resource, copy it to App_LocalResources.
Create additional resource files for each language or language and culture (name) that you want to support in your application. You can do either of the following:
Copy the first resource file to a new name that includes the language or language and culture information, and then translate the contents of the value elements to another language.
Repeat Steps 1 through 5 with the same key/value pairs, but with the values translated to another language. For the file name in step 5, include the language or language and culture names.
For example, the Spanish version of the SiteResources.resx file would be
When naming resource files, do not include
.aspxin the name, because this can result in a naming conflict. For example, the Resource folder cannot contain two files with names such
resTestPage.aspx.resxbecause the resolution of the file names at compile-time would create a naming conflict, resulting in a compile-time error.