My.Extensions.Localization.Json
4.1.0
dotnet add package My.Extensions.Localization.Json --version 4.1.0
NuGet\Install-Package My.Extensions.Localization.Json -Version 4.1.0
<PackageReference Include="My.Extensions.Localization.Json" Version="4.1.0" />
<PackageVersion Include="My.Extensions.Localization.Json" Version="4.1.0" />
<PackageReference Include="My.Extensions.Localization.Json" />
paket add My.Extensions.Localization.Json --version 4.1.0
#r "nuget: My.Extensions.Localization.Json, 4.1.0"
#:package My.Extensions.Localization.Json@4.1.0
#addin nuget:?package=My.Extensions.Localization.Json&version=4.1.0
#tool nuget:?package=My.Extensions.Localization.Json&version=4.1.0
My.Extensions.Localization.Json
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();
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Localization (>= 2.3.0)
- Microsoft.Extensions.Localization (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
NuGet packages (17)
Showing the top 5 NuGet packages that depend on My.Extensions.Localization.Json:
| Package | Downloads |
|---|---|
|
HiP.Mvc
Hi-P MVC相关基础包,含基础后台管理功能 |
|
|
Dignite.Abp.Localization
Package Description |
|
|
Dignite.Abp.MultiTenancyLocalization
Package Description |
|
|
ZhonTai.Admin.Core
中台Admin权限管理核心库 |
|
|
Dignite.Abp.TenantLocalization
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.