我參考這篇https://learn.microsoft.com/zh-tw/aspnet/core/fundamentals/localization?view=aspnetcore-6.0
但是最後輸出的時候都只有輸出名稱不會輸出值
以下是程式碼
Controller的部分
private readonly IStringLocalizer<testController> _localizer;
public testController(IStringLocalizer<testController> localizer,
IStringLocalizer<SharedResource> sharedLocalizer)
{
_localizer = localizer;
}
[HttpGet]
public string Get()
{
return _localizer["test"] + _localizer["test"].Value;
}
Program的部分只有加上這一部分
builder.Services.AddControllersWithViews();
builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
builder.Services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
有人知道我哪裡有寫錯或少加東西嗎....
已解決,詳細參考這篇
https://www.codeproject.com/Articles/5324504/Localization-in-ASP-NET-Core-Web-API