Creating multilingual Site Definitions with Visual Studio 2010 SharePoint Development Tools


When working on SharePoint Solutions one of the common requirements is delivering multilingual solutions. Depending on your scenario you might either need to localize a single Web Part or a complete Solution. Thinking of multiple languages you have to take into account not only the development but also the packaging process for all the different assets in your Solution. One of such assets, where implementing support for multiple languages in SharePoint 2010 might seem complex at first sight, are Site Definitions. However you can easily create a multilingual Site Definition using nothing more than the standard capabilities  of the new Visual Studio 2010 SharePoint Developer Tools.

If you look at the new Visual Studio 2010 SharePoint Developer Tools, it seems like they have no support for localizing custom Site Definitions at first. If you create a custom Site Definition using the standard toolset, you get a Site Definition that is bound to a specific language by the Deployment Location of the WebTemp*.xml file.

Custom Site Definition created using the Visual Studio 2010 SharePoint Developer Tools

As you might know, localized Site Definitions share all the resources except for the WebTemp*.xml file. The WebTemp*.xml file contains the localized names of the specific Configurations and points to the shared onet.xml file. While the name of the WebTemp*.xml file doesn’t matter that much (as long as it matches the WebTemp*.xml pattern) it is a good practice to append the the identifier of your custom Site Collection to the WebTemp prefix to make it easier to track all Site Definitions installed in the Farm.

If you look at the custom Site Definition that gets created by the Visual Studio 2010 SharePoint Developer Tools you might see one challenge with delivering a multilingual Site Definition. As you can see all files (default.aspx, onet.xml and WebTemp*.xml) are in the same directory. In order to deliver the translated version of your Site Definition in another language you would have to create a copy of the WebTemp*.xml file, but you cannot have two files with the same name in the same directory, can you? So what are the options?

A few approaches that are not quite what you really want…

First of all you could create a new Site Definition project for every translation of your Site Definition. By sharing the common files like pages and onet.xml you could get the job done, but it would make the packaging process unnecessarily complex. First of all you would have a few projects with only a couple of files, and additionally you would end up hacking the identifiers to get it all right.

Another thing that you might try is to choose a different name for every WebTemp*.xml file, for example one that includes the locale like: WebTempMySiteDef1033.xml. This would definitely work and it would allow you to get it all done within a single project. It would be quite quirky though with all the different names and definitely not intuitive for someone not involved with the project during the development stage as it doesn’t follow the good practices. But there is however one more approach worth trying…

Creating multilingual Site Definitions the proper way

One more thing that you could do is to create a directory named after the locale for every language that your Site Definition should support. That would allow you to use the same names for the WebTemp*.xml files and would prevent you from using hacks and dodgy workarounds.

The first step in this approach is to create a regular Site Definition using the Site Definition SharePoint Project Template.

Creating a custom Site Definition using the Site Definition SharePoint Project Template

Then you would create a directory named after locale for every locale that your Site Definition must support:

Custom directories created for every locale supported by the Site Definition

The next step is to move the original WebTemp*.xml file to one of the locale directories and copy it to all the other locale directories translating the contents to match the locale:

Site Definition with folders for every locale supported. Each locale folder contains a WebTemp*.xml file named after the Site Definition.

The final piece of the puzzle is to change the Deployment Location of each of the WebTemp*.xml files so that they are deployed to the location specified by the locale folder. You can do that using the Properties Window of every WebTemp*.xml file:

Changing the Deployment Location for a WebTemp*.xml file using the Properties Window

And that’s it. Using this simple solution you can develop and package a multilingual Site Definition using the standard capabilities of the Visual Studio 2010 SharePoint Developer Tools and not a single hack!

Technorati Tags: SharePoint 2010,Visual Studio 2010

Others found also helpful: