Arnoldus The Multi Language Site in C#

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



This is the continuation of Part 3.1 (Multi Language Site: "Loose Strings": Global Resource Files)


Sitemap Files

A standard SiteMap file looks something like:


<?xmlversion="1.0"encoding="utf-8" ?>
<siteMap>
<siteMapNodetitle="Home"url="Default.aspx">
<siteMapNodetitle="Albums"url="MediaGallery.aspx" />
<siteMapNodetitle="Search"url="Search.aspx" />
<siteMapNodetitle="About Me"url="AboutMe.aspx" >
<siteMapNodetitle="Publications"url="Publications.aspx" />
</siteMapNode>
<siteMapNodetitle="GuestBook"url="Guests.aspx" >
<siteMapNodetitle="Sign GuestBook"url="SignGuest.aspx" />
</siteMapNode>
<siteMapNodetitle="Download"url="DownloadNet.aspx" >
<siteMapNodetitle="Download Library"url="DwnlLibrary.aspx" />
</siteMapNode>
<siteMapNodetitle="Manage"url="Private/Manage.aspx" />
</siteMapNode>
</siteMap>


Modified for localization the sitemap becomes:


<?xmlversion="1.0"encoding="utf-8" ?>
<siteMapenableLocalization="true" xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNodeurl="Default.aspx" resourceKey="HomePage">
    <siteMapNodeurl="MediaGallery.aspx" resourceKey="AlbumsPage" />
          <siteMapNodeurl="Search.aspx" resourceKey="SearchPage" />
          <siteMapNodeurl="AboutMe.aspx" resourceKey="AboutPage" >
               <siteMapNodeurl="Publications.aspx" resourceKey="PubsPage" />
          </siteMapNode>
          <siteMapNodeurl="Guests.aspx" resourceKey="GuestPage" >
                <siteMapNodeurl="SignGuest.aspx" resourceKey="SGuestPage" />
          </siteMapNode>
          <siteMapNodeurl="DownloadNet.aspx" resourceKey="DwnlPage" />
          <siteMapNodeurl="Private/Manage.aspx" resourceKey="PrivatePage" />
    </siteMapNode>
</siteMap>


The localizations are stored in Global Resource Files (also stored in the “App_GlobalResources” directory) with names like: “web.sitemap.resx“, “web.sitemap.it-IT.resx“ and “web.sitemap.nl-NL.resx“, just like the other global resource files. The sitemap resource files contain dictionaries just like the other resource files. For instance, web.sitemap.resx (default language):

NameValue
AboutPage.DescriptionPersonal Info about the Author
AboutPage.TitleAbout Me


This translates into Italian (web.sitemap.it-IT.resx) as:

NameValue
AboutPage.DescriptionInformazione su l'autore
AboutPage.TitleSu di me


or Dutch (web.sitemap.nl-NL.resx) as:

NameValue
AboutPage.DescriptionInformatie over de auteur
AboutPage.TitleOver mij


The .Title fields are the ones displayed in the navigation menus, while the .Description fields function as tool tips.

Using Visual Studio 2008, you have to create and populate the files manualy. When populating the files, VS2008 throws a warning for each item you enter (an exclamation mark in a red bullet), which results in the warning: The resource name 'xxx.yyy' is not a valid identifier. This warning can be safely ignored. You can view the underlying (valid) xml code by using the "view code" item from the context menu which shows the correct xml code that is the real content of the files.


Continue to: Multi Language Site: "Loose Phrases" (Part 3.3): Local Resource Files.