Search code examples
asp.net-core-mvc

One resource file per language for entire asp.net core project


Is it possible to just have only one resource file (per language) for the entire project in stead of per controller and per view (as mentioned in the manual https://docs.asp.net/en/latest/fundamentals/localization.html)?

A resource file per controller and language seems a bit overkill.


Solution

  • Yes, that is possible. You've to override StringLocalizer and StringLocalizerFactory. With those custom you can store resource in one or many files, in the database or in the JSON files. Or do other magic...

    And then all you need to do is to register your custom service:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddSingleton<IStringLocalizerFactory, YOUR_LOCALIZER_FACTORY>();
    }