惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tenable Blog
Last Week in AI
Last Week in AI
P
Proofpoint News Feed
Engineering at Meta
Engineering at Meta
H
Help Net Security
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 司徒正美
量子位
N
Netflix TechBlog - Medium
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
Recorded Future
Recorded Future
博客园 - 三生石上(FineUI控件)
Vercel News
Vercel News
aimingoo的专栏
aimingoo的专栏
I
InfoQ
Microsoft Security Blog
Microsoft Security Blog
Scott Helme
Scott Helme
The Last Watchdog
The Last Watchdog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
AI
AI
WordPress大学
WordPress大学
Security Archives - TechRepublic
Security Archives - TechRepublic
Google Online Security Blog
Google Online Security Blog
U
Unit 42
V2EX - 技术
V2EX - 技术
MongoDB | Blog
MongoDB | Blog
Schneier on Security
Schneier on Security
博客园 - Franky
H
Heimdal Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Jina AI
Jina AI
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
N
News | PayPal Newsroom
S
Securelist
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
罗磊的独立博客
H
Hackread – Cybersecurity News, Data Breaches, AI and More
雷峰网
雷峰网

博客园 - 王伟晔

docker 主从mysql配置 利用asp.net Core开发webapi对接云之家智能审批数据互联控件 Windows 2012安装odoo12 Windows有点腻了?不如试试Ubuntu. 处理范例代码Webapi中的Mongodb的Bson中ObjectId反序列化异常 重建程序员能力(3)-asp.net MVC框架增加Controller 重建程序员能力(2)-如何使asp.net mvc应用增加js和其他功能 重建程序员能力(1) asp.net mvc 5发布部署遇到403.14 我需要在Web上完成一个图片上传的功能(+2) 我需要在Web上完成一个图片上传的功能后续(+1) 我需要在Web上完成一个图片上传的功能 android-studio-bundle-141.1980579-windows download Site Razor提高WebPage代码的易读性 C# Hello World - 王伟晔 用params关键字增强代码的可读性 陌生的yield关键字 发现Visual Studio隐含的大礼包--漂亮的Visual Studio图像库 职业程序员必须要有的工作态度(之一)
用app.net Core搞掂多国语言网站
王伟晔 · 2017-05-23 · via 博客园 - 王伟晔

Asp.net Core 中文文档很少,你可以看英文的,不过英文的也是说的有点乱。这篇文章是干货。

1. 配置好你的WebApplication,使他可以支持国际化语言,修改文档Startup.cs

        publicvoid ConfigureServices(IServiceCollection services)

        {

            services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.AddMvc()

              .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)

              .AddDataAnnotationsLocalization();

        }

2.修改好你的配置

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

{...

这里面写你的网站需要支持的语言。

            var supportedCultures = new[]

            {

                new CultureInfo("en-US"),

                new CultureInfo("zh-CN")

            };

这里是写你的默认语言的

            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"]

测试运行

搞点。