My.Extensions.Localization.Json
March 7, 2026 ยท View on GitHub
JSON Localization Resources for ASP.NET Core.
Installation
dotnet add package My.Extensions.Localization.Json
Usage
1. Register JSON Localization Services
Adds the JSON localization services into DI by adding AddJsonLocalization in Program.cs or Startup.cs, as follows:
builder.Services.AddJsonLocalization(options =>
{
options.ResourcesPath = new[] { "Resources" };
options.ResourcesType = ResourcesType.TypeBased;
});
2. Create Resource Files
Your localization resource should be placed based on the ResourcesPath folder, similar to the default .resx-based localization, but using JSON files instead. The file naming convention depends on the ResourcesType configuration.
The resource file should be valid JSON objects with key-value pairs, each representing a localized string:
{
"Hello": "Bonjour",
"WelcomeMessage": "Bienvenue sur notre application !"
}
2.1 Type-Based
The resource files are named based on the types that use the IStringLocalizer. For more information, please refer to the Resource file naming in the ASP.NET Core Globalization and localizations docs.
2.2 Culture-Based
The resource files are named based on the supported cultures, for example, ar.json.
3. Use in Your Application
You can use the IStringLocalizer normally in your application.
public class HomeController : Controller
{
private readonly IStringLocalizer<HomeController> _localizer;
public HomeController(IStringLocalizer<HomeController> localizer)
{
_localizer = localizer;
}
public IActionResult Index()
{
ViewData["Message"] = _localizer["WelcomeMessage"];
return View();
}
}