net core 3.1 Global

NET CORE 3.1多语言

控制器多语言
ConfigureServices 1

services.AddLocalization(o =>
{
o.ResourcesPath = "Resources";
});
services.AddMvc();

Configure 2
IList<CultureInfo> supportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("zh-CN"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-US"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});

3
private readonly IStringLocalizer<HomeController> _localizer;
public HomeController( IStringLocalizer<HomeController> localizer)
{
_localizer = localizer;
}
public IActionResult Hello()
{
return Content(_localizer["Hello"]);
}
4.
Resources/Controllers/HomeController.en-US.resx Hello HELLO
Resources/Controllers/HomeController.zh-CN.resx Hello 你好

https://localhost:44398/home/hello
https://localhost:44398/home/hello?ui-culture=zh-CN
https://localhost:44398/home/hello?ui-culture=en-US
----------------------------------------------------
视图多语言
ConfigureServices 1
services.AddMvc().AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix);
2. HomeController
public IActionResult Hello()
{
return View();

}
3.
Views/Home/Hello.zh-CN.resx GoodBye 再见
4.Hello.cshtml

@using Microsoft.AspNetCore.Mvc.Localization

@inject IViewLocalizer Localizer
@{
ViewData["Title"] = "Hello";
}

<h1>Hello</h1>

<h2>@Localizer["GoodBye"]</h2>
4.


https://localhost:44398/home/hello
https://localhost:44398/home/hello?ui-culture=zh-CN
https://localhost:44398/home/hello?ui-culture=en-US

前端 VUE请求 HEADER 

const config = {
headers: {
"accept-language": "en-US,zh;q=0.9,en;q=0.8"
}
}

       axios.post('', '', config)

原文地址:https://www.cnblogs.com/LiuFengH/p/13052183.html