Resource Files
There are a lot of “loose strings” that do not merit storage in a database but need to be tied anyway. For instance, prompts like: “Your Name Please”, in a webform, or “Viewed x Times” (where x is a number returned from a database query).
There are two solutions two such problems: Global Resource Files and Local Resource Files. They behave sin the same way, but, if you use some version of Visual Studio 2008, you find more support for local resource files than for global resource files.
Global Resource Files
If you use global resource files, you create one for each language that you want to handle. The files are created in a special directory: "App_GlobalResources" The names of the files are like: "Resource.resx" for the default language of the site, and files such as: "Resource.it-IT.resx" for Italian and "Resource.nl-NL.resx" for Dutch. Note: that the lower case language part e.g. "it" denotes the language while the uppercase "IT" denotes the culture: Italian as spoken in Italy rather than the Swiss italian dialect. You must then create variables for each word or phrase you need in each resource file. For instance, the Resource.resx file could contain:
|
| Name | Value | | BlogCat | View blog entries on the topic of | | BlogCatHead | Blog Categories |
|
|
While the Resource.nl-NL.resx file would show:
|
| Name | Value | | BlogCat | Zie blog artikelen over het onderwerp | | BlogCatHead | Blog Categorieën |
|
|
The Resource.it-IT.resx file would contain:
|
| Name | Value | | BlogCat | Vedi entrate nel blog su l’argomento di | | BlogCatHead | Categorie di Blog |
|
|
To display this in a page from the code-behind, you would use code like:
|
HyperLink lnkPickCategory = (HyperLink)(DataList1.Items[0].FindControl ("lnkPickCategory"));
if (lnkPickCategory != null)
{
lnkPickCategory.ToolTip = Resources.Resource.BlogCat + " " + lnkPickCategory.Text;
}
/div>
|
|
There is a special case of global resource files which are used to localize the sitemap file. These will be discussed in the next part: Multi Language Site: "Loose Phrases" (Part 3.2): Sitemap Files.
|