net core 3.1 Global
2021-02-10 11:20
标签:多语言 public user addm service ODB asp oca microsoft NET CORE 3.1多语言 控制器多语言 services.AddLocalization(o => Configure 2 3 https://localhost:44398/home/hello @using Microsoft.AspNetCore.Mvc.Localization @inject IViewLocalizer Localizer net core 3.1 Global 标签:多语言 public user addm service ODB asp oca microsoft 原文地址:https://www.cnblogs.com/LiuFengH/p/13052183.html
ConfigureServices 1
{
o.ResourcesPath = "Resources";
});
services.AddMvc();
IList
{
new CultureInfo("en-US"),
new CultureInfo("zh-CN"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-US"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
private readonly IStringLocalizer
public HomeController( IStringLocalizer
{
_localizer = localizer;
}
public IActionResult Hello()
{
return Content(_localizer["Hello"]);
}
4.
Resources/Controllers/APIController.en-US.resx Hello HELLO
Resources/Controllers/APIController.zh-CN.resx 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
@{
ViewData["Title"] = "Hello";
}Hello
@Localizer["GoodBye"]
4.
https://localhost:44398/home/hello
https://localhost:44398/home/hello?ui-culture=zh-CN
https://localhost:44398/home/hello?ui-culture=en-US
上一篇:CSS—总结常用垂直居中方法
下一篇:生产环境 webpack 配置
文章标题:net core 3.1 Global
文章链接:http://soscw.com/index.php/essay/53549.html