I'm working on a ASP.NET Core project with resource files organized like this:
project/Resources/
- resource.resx
- resource.en.resx
- resource.en-GB.resx
- resource.en-US.resx
When the project is built, it generates a class named resource.Designer.cs next to the .resx file, containing a ResourceManager property among others:
private static global::System.Resources.ResourceManager resourceMan;
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
public static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("project.Resources.resource", typeof(MyWebApp).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
In my views, resources are accessed like this:
@using Resource = project.Resources.Resource;
<span>@Resource.WelcomeMessage</span>
Now I need to introduce a domain-specific logic, with different resource sets for each domain, superior to the language layer. So, for different domains, the resources would be organized like:
project/Resources/Domain1/
- resource.resx
- resource.en.resx
- resource.en-GB.resx
- resource.en-US.resx
project/Resources/Domain2/
- resource.resx
- resource.en.resx
- resource.en-GB.resx
- resource.en-US.resx
However, in my views, the reference to the resource class through the Designer.cs files is statically bound to a fixed namespace. This setup does not account for the dynamic nature of selecting resource files based on the current domain.
My goal is finding a way to dynamically adjust this static reference in the views to point to the correct Designer.cs file that corresponds to the specified domain, effectively allowing for domain-specific resources without altering the static access pattern established in the views.
I've also considered renaming the .resx files to incorporate the domain directly in their names, like so:
project/Resources/
- resource.domain1.resx
- resource.domain1.en.resx
- resource.domain1.en-GB.resx
- resource.domain1.en-US.resx
Additionally, I've explored the possibilities offered by IStringLocalizerFactory and IViewLocalizer. However, both of these solutions seem to require significant changes to the existing resource calling mechanisms in my legacy code, which I'm trying to avoid.
What's the simplest way to support different resource sets based on the domain without modifying the existing access pattern in views?
Thanks for your insights!