WeihanLi.Extensions.Localization.Json
2.0.0
Prefix Reserved
dotnet add package WeihanLi.Extensions.Localization.Json --version 2.0.0
NuGet\Install-Package WeihanLi.Extensions.Localization.Json -Version 2.0.0
paket add WeihanLi.Extensions.Localization.Json --version 2.0.0
#r "nuget: WeihanLi.Extensions.Localization.Json, 2.0.0"
#:package WeihanLi.Extensions.Localization.Json@2.0.0
#addin nuget:?package=WeihanLi.Extensions.Localization.Json&version=2.0.0
#tool nuget:?package=WeihanLi.Extensions.Localization.Json&version=2.0.0
WeihanLi.Extensions.Localization.Json 
Intro
dotnet JSON file based localization
Build
GetStarted
register required services:
services.AddJsonLocalization(options =>
{
options.ResourcesPath = Configuration.GetAppSetting("ResourcesPath");
options.ResourcesPathType = ResourcesPathType.TypeBased; // by default, looking for resourceFile like Microsoft do
// options.ResourcesPathType = ResourcesPathType.CultureBased; // looking for resource file in culture sub dir see details follows
});
middleware config(the same with before):
app.UseRequestLocalization();
That's it~
Add your resource files
TypeBasedResourcePath
For Types:
Home/Index ⇒ Controllers/HomeController
the resource path looking for:
- Controllers/HomeController.[cultureName].json
for example:
- Resources/Controllers/HomeController.en.json
- Resources/Controllers/HomeController.zh.json
For RazorViews:
for example:
- Resources/Views/Home/Index.en.json
- Resources/Views/Home/Index.zh.json
CultureBasedResourcePath
For Types:
Home/Index ⇒ Controllers/HomeController
the resource path looking for:
- Resources/[cultureName]/Controllers/HomeController.json
for example:
- Resources/en/Controllers/HomeController.json
- Resources/zh/Controllers/HomeController.json
For RazorViews:
for example:
- Resources/en/Views/Home/Index.json
- Resources/zh/Views/Home/Index.json
Copy your resource files to output:
you had to set resource files copy to output to make it works normal
add the follows sample config to your startup project file:
Always
the config above is made to make sure your json resource files in Resources dir copied to output, change it if you need
Use
just like what you do before:
Controller sample:
public class ValuesController : Controller
{
private readonly IStringLocalizer _localizer;
public ValuesController(IStringLocalizer localizer)
{
_localizer = localizer;
}
// GET: api/
[HttpGet]
public string Get()
{
return _localizer["Culture"];
}
}
Razor View Sample:
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Localization
@using WeihanLi.Extensions.Localization.Json.Sample.Controllers
@inject IHtmlLocalizer HtmlLocalizer
@inject IStringLocalizer StringLocalizer
@inject IViewLocalizer ViewLocalizer
@{
ViewData["Title"] = "Index";
}
Index
string: @StringLocalizer["Hello"]
html: @HtmlLocalizer["Hello"]
view: @ViewLocalizer["Hello"]
Resource file sample:
{
"Culture": "English"
}
Samples
Contact
Contact me via weihanli@outlook.com if you need
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Localization.Abstractions (>= 2.1.0)
- System.Text.Json (>= 6.0.0)
- WeihanLi.Common (>= 1.0.60)
-
net6.0
- Microsoft.Extensions.Localization.Abstractions (>= 6.0.0)
- WeihanLi.Common (>= 1.0.60)
-
net8.0
- Microsoft.Extensions.Localization.Abstractions (>= 8.0.0)
- WeihanLi.Common (>= 1.0.60)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on WeihanLi.Extensions.Localization.Json:
| Package | Downloads |
|---|---|
|
DuMes.Expansion.FastEndpoints
多脉Endpoints操作基础库 |
|
|
DuMes.Expansion.WebApi
多脉WebApi扩展包括:语言、跨域、Swagger、WebApi、JWT生成和解析、JWT过滤器 |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on WeihanLi.Extensions.Localization.Json:
| Repository | Stars |
|---|---|
|
WeihanLi/DbTool
数据库工具,根据表结构文档生成创建表sql,根据数据库表信息导出Model和表结构文档,根据文档生成数据库表,根据已有Model文件生成创建数据库表sql
|
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.0 | 2,555 | 11/24/2023 |
| 1.0.3 | 7,436 | 3/22/2020 |
| 1.0.2 | 901 | 1/31/2020 |
| 1.0.1 | 757 | 1/15/2020 |
| 1.0.1-preview-20200115-163444 | 625 | 1/15/2020 |