Reputation: 1528
I am new to asp.net core localization, and trying to use resource files. There are multiple ways of doing it, so I started with IStringLocalizer and IHtmlLocalizer.
We can specify the type while injecting the Localizer into the view, and most of the tutorial recommend to create an Empty SharedResource class file with root namespace.
I tried to find the reason behind it but didn't find, Could anyone please help me out about the reason of having the empty SharedResource class?
@inject IHtmlLocalizer<SharedResources> Localizer
namespace Root.Namespace
{
public class SharedResources
{
}
}
Upvotes: 4
Views: 207
Reputation: 20132
empty SharedResource class is use to group your resource file in Visual studio like this
Also it need for IStringLocalizeFactory
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddDataAnnotationsLocalization(options =>
{
options.DataAnnotationLocalizerProvider = (type, factory) =>
{
var assemblyName = new AssemblyName(typeof(SharedResource).GetTypeInfo().Assembly.FullName);
return factory.Create("SharedResource", assemblyName.Name);
};
});
You can read my blog and source code here to understand it better
Upvotes: 0