Moving on with WebParticles 3

Localizing the user control web part

This post adds to Tony Rabun’s post “WebParticles: Developing and Using Web User Controls WebParts in Microsoft Office SharePoint Server 2007“. Here I show how you can use ASP.NET Local Resource files to localize the strings in the user control that will be wrapped as a web part.

  1. Open the user control in Design view.

  2. Select Generate Local Resource from the Tools menu.

  3. This will generate the <UserControlName>.resx resource file. This resource file will hold the default culture strings. You need to copy/paste this file and rename the new copy adding the culture and locale to the resource file name before the .resx. (“ar-jo” in my case). In the new file you can write the localized strings.

Figure 1 – Generating a resource file for the user control

  1. Change the Build Action property of the resx file to Embedded Resource. This compiles the default resource file into the main assembly of the project and the localized resource files into satellite assemblies.

Figure 2 – Changing the Build Action property to Embedded Resource

Figure 3 – Satellite assembly created in ar-jo folder

  1. Add the code to access the compiled resource files to the code behind of the user control.

Figure 4 – Accessing localized strings from compiled resource files within the code

  1. Copy the new assemblies (main and satellite) to the _app_bin folder or the GAC depending on how you are deploying your solution.