標籤:ted cti data value path actor orm 資源檔 str
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.resxc.在資源檔中添加Key 和Value d.視圖頂部@using Microsoft.AspNetCore.Mvc.Localization@inject IViewLocalizer Localizer 需要顯示的字串中將Learn More 修改 @Localizer["Learn More"] 測試回合搞點。
用app.net Core搞點多國語言網站