Hub-and-Spoke model & Satellite Assemblies

The .NET Framework uses a hub-and-spoke model to locate and retrieve localized resources, which requires that resources must be placed in specific locations so that they can be easily located and used.

If the resources are not compiled and named as expected, or not placed in correct locations, the CLR will not be able to locate them and will use the resources of the default culture instead.

The hub is the main assembly that contains the non-localizable executable code and the resources for a single culture, which is called the neutral or default culture. The default culture is the fallback culture for the application and is used when no localized resources are available. You use the NeutralResourcesLanguageAttribute attribute to designate the culture of the application's default culture.

Each spoke connects to a satellite assembly that contains the resources for a single localized culture but does not contain any code. Satellite assemblies are not part of the main assembly. The resources of satellite assemblies that correspond to a specific culture can easily be updated or replaced without replacing the main assembly for the application.

The .NET Framework Resource Manager, represented by a ResourceManager object, is used to automatically access localized resources and has the following requirements:
  • A single satellite assembly must include all the resources for a particular culture.
  • There must be a separate subdirectory in the application directory for each localized culture that stores that culture's resources. The subdirectory name must be the same as the culture name.
    Alternately, you can store your satellite assemblies in the GAC. In this case, the culture information component of the assembly's strong name must indicate its culture.
    If your application includes resources for subcultures, place each subculture in a separate subdirectory under the application directory.
  • The satellite assembly must have the same name as the application, and must use the file name extension ".resources.dll". Ex: If an application is named Example.exe, the name of each satellite assembly should be Example.resources.dll.
  • Information about the culture of the satellite assembly must be included in the assembly's metadata. To store the culture name in the satellite assembly's metadata, you specify the /culture option when you use Assembly Linker to embed resources in the satellite assembly.

No comments:

Post a Comment