Localizable vs. Non-localizable Resources

Release 1.0 - ...

Localizable resources are resources that require translation, e.g. strings for the user interface. By Smartsite convention, localizable resources should be embedded in satellite assemblies, each containing the translated resources for a specific culture. The satellite resource libraries are placed in separate subfolders of the main assembly, one folder per supported culture. Resources embedded in a satellite assembly may be overridden or extended by a custom xml resource file placed in the same folder as the satellite assembly.

Non-localizable resources are culture-independent and are never translated, e.g. filenames, XML files, bitmaps, icons, etc. Such resources are embedded into the main assembly and cannot be overridden or extended by a custom resource file.

A. To add a resource file to a project:
  1. Open the Solution Explorer
  2. Open the context menu of the project
  3. Select Add, New Item…
  4. Select Resource File
  5. Enter a name for the resource file
  6. Select OK
  7. Double click on the new resource file to open the Resource Editor

By default, Visual Studio will embed the resource file into the assembly and use the standard ResXFileCodeGenerator custom tool to generate an associated strongly-typed resource class.

B. To add a localizable resource file to a project:
  1. Add a resource file as described in (A)
  2. Select the resource file in the Solution Explorer
  3. Open the Properties Window
  4. Change the value of the property Custom Tool to SmartsiteResXFileCodeGenerator (requires a reference to Smartsite.Tools)
  5. Open the Project Properties, tab Application, Assembly Information
  6. Combo Neutral Language, select the language of the default resources (en-US)
  7. Save and close the Project Properties
  8. Make a copy of the resource file (using Explorer)
    Assign the same filename as the original resource file, but prepend the name of another culture (i.e. Resources.nl-NL.resx) to the extension.
  9. Switch to Visual Studio and open the Solution Explorer
  10. Click on Show All Files
  11. Select the newly made copy of the resource file
  12. Open the context menu and select Include in Project

Repeat steps 5-9 to add translated resources for other cultures. When the application is compiled, Visual Studio will create subfolders below the main assembly containing satellite resource assemblies for each available culture. When the application requests a localized resource, the resource manager will return a resource value from the satellite assembly that has the closest match to the current UI culture.

The embedded resource will serve as the ultimate fall-back resource; if a resource is requested for a certain culture but no matching resource satellite assembly exists, then the manager returns a value from the embedded neutral resource file.

Because the neutral resource file uses the Smartsite custom tool, the associated strongly-typed resource class internally creates a SmartsiteResourceManager, allowing the embedded resources to be overriden/extended by a custom xlm resource file.

C. To expose resources from a class library and consume them from a client app:
  1. Create a class library project
  2. Add localized resource file for one or more cultures as descibed in (B)
  3. Ensure that the neutral resource file uses the SmartsiteResXFileCodeGenerator custom tool. The SmartsiteResXFileCodeGenerator custom tool declares the generated resource class and it's properties with public scope, so they are visible to external projects.
  4. Create a client project
  5. Add a (project) reference to the previously created resource library
  6. Now you can retrieve resources exposed by the public resource class in the referenced resource library.

Note: Smartsite Source Control contains a solution ResLibDemo in the folder Test Projects that demonstrates the different methods.