public
void
Configure(
IApplicationBuilder
app,
IHostingEnvironment
env,
ILoggerFactory
loggerFactory)
{...
这里面写你的网站需要支持的语言。
};
这里是写你的默认语言的
app.UseRequestLocalization(
new
RequestLocalizationOptions
{
DefaultRequestCulture =
new
RequestCulture
(
"en-US"
),
// Formatting numbers, dates, etc.
SupportedCultures = supportedCultures,
// UI strings that we have localized.
SupportedUICultures = supportedCultures
});
}
3.给你的视图增加资源文档
a.增加Resources目录
b.按你的视图路径,给出资源文档的结构 例如你的视图Views\Home\Index.cshtml 你的资源Resources\Views\Home\Index.zh-CN.resx 或 Resources\Views\Home\Index.en-US.resx
c.在资源文件中添加Key 和Value
d.视图顶部
@
using
Microsoft.AspNetCore.Mvc.Localization
@inject
IViewLocalizer
Localizer
需要显示的字符串中
将
Learn More 修改
@Localizer[
"Learn More"
]
测试运行
搞点。