I am new to .netcore stuff. I recently came through a piece of code in which the author uses some SharedLocalizer["SomeWords"]
. I tried to search for the it everywhere, but sadly couldn't find enough explained information. What is the working of SharedLocalizer?

- 301
- 1
- 3
- 19
-
First google search result was https://damienbod.com/2017/11/01/shared-localization-in-asp-net-core-mvc/ . Does it look like what you've seen? – Mustafa Gursel Jun 25 '19 at 13:27
2 Answers
I think what you mean is SharedResource
,to use a shared resource file in a view, inject IHtmlLocalizer:
@using Microsoft.AspNetCore.Mvc.Localization
@inject IHtmlLocalizer<SharedResource> SharedLocalizer
<h1>@SharedLocalizer["Hello!"]</h1>
ASP.NET Core MVC razor views and view models can use localized strings from a shared resource. This saves you creating many different files and duplicating translations for the different views and models. This makes it much easier to manage your translations, and also reduces the effort required to export, import the translations.
SharedResources.cs
can be placed in the root folder of project or in Resources folder, but the most important thing is that namespace should be set to the root of the project.
namespace ProjectRoot // Not "ProjectRoot.Resources"
{
public class SharedResource
{
}
}
Refer to ASP.NET Core Localization with help of SharedResources https://github.com/aspnet/AspNetCore.Docs/issues/6830

- 19,118
- 10
- 37
- 53
SharedLocalizer is used to generate the HTML page in different locale. You should refer this document for a detailed explaination

- 4,746
- 1
- 24
- 35