Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I combine local resources in satellite assemblies?

I have a lot of local resourse files

  • /Controls/App_LocalResources/SomeControl.ascx.resx,
  • /Pages/App_LocalResources/SomePage.aspx.resx, etc.

I want to add another language and I do not want to go through all folders and add SomeControl.ascx.de.resx files for example and then have to recompile the whole think.

I would like to use satellite assemblies and embed all the files into something like MyWebPage.de.dll

This was possible in VS2003 version for global resources, but I'm not sure can I do it in VS2008 version for local resources?

I am accessing the resource with the syntax:

<asp:label id="lblSomething" runat="server" meta:resourcekey="labelFirstName"/>
like image 482
ron Avatar asked Oct 29 '09 11:10

ron


People also ask

What is a satellite assembly and how it is being used?

A satellite assembly is a . NET Framework assembly containing resources specific to a given language. Using satellite assemblies, you can place resources for different languages in different assemblies, and the correct assembly is loaded into memory only if the user selects to view the application in that language.

What is a satellite resource?

A satellite assembly is a compiled library (DLL) that contains “localizable” resources specific to a given culture such as strings, bitmaps, etc. You are likely to use satellite assemblies when creating a multilingual UI application.


1 Answers

Your question isn't really too clear on whether you are looking for a feature of VS2008 or a feature of the ASP.NET framework. So I'll go with the code solution.

The implicit binding syntax you're using uses ASP.NET's default LocalResourceProvider which takes in the path of page under which the resources live to work out which resources to load. If your resources are stored elsewhere and you still want to use the implicit binding systax in your code in front you'll need to use your own Provider. Sounds complicated but it's fairly straightforward.

To do this you'll need to first subclass ResourceProviderFactory

and override both

IResourceProvider CreateGlobalResourceProvider(string classKey)
IResourceProvider CreateLocalResourceProvider(string virtualPath)

...then implement your own IResourceProvider that gets your resources from your satellite assemblies using a ResourceManager

public interface IResourceProvider
{
     object GetObject(string resourceKey, CultureInfo culture);
     IResourceReader ResourceReader { get; }
}

You then need to add configuration to your web.config file to let ASP.NET know to use your SatelliteResourceProviderFactory and move your resources in to your external assemby, but that should be you good to go.

Plenty of documentation can be found here...under the "Building a Database Resource Provider" section...

http://msdn.microsoft.com/en-us/library/aa905797.aspx#exaspnet20rpm_topic4

like image 94
ChrisV Avatar answered Oct 13 '22 11:10

ChrisV