Arnoldus The Multi Language Site in C#

Multi Language Site: “Loose Strings” (Part 3.1)



This is the first section of the Third Part: Multi Language Site: "Loose Strings" (Part 3.1)


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:

NameValue
BlogCatView blog entries on the topic of
BlogCatHeadBlog Categories


While the Resource.nl-NL.resx file would show:

NameValue
BlogCatZie blog artikelen over het onderwerp
BlogCatHeadBlog Categorieën


The Resource.it-IT.resx file would contain:

NameValue
BlogCatVedi entrate nel blog su l’argomento di
BlogCatHeadCategorie 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.