你好
我嘗試學習ASP.NET Core 3.0 下編程本地化的功能,我在startup.cs改了以下編碼便不懂得怎樣做了,想請教一下應該還有什么需要做?
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(o =>
{
o.ResourcesPath = "Resources";
});
var connection = Configuration.GetConnectionString("theManagerDB");
services.AddDbContext<theManagerContext>(options => options.UseSqlServer(connection));
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddEntityFrameworkStores<theManagerContext>(); //original : ApplicationDbContext
//services.AddMvc();
services.AddControllersWithViews();
services.AddRazorPages();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseDatabaseErrorPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
IList<CultureInfo> supportedCultures = new List<CultureInfo>
{
new CultureInfo("en-US"),
new CultureInfo("zh-CN"),
new CultureInfo("zh-TW"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-US"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=UserRecords}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
}
}
UserRecordsController
public class UserRecordsController : Controller
{
private readonly theManagerContext _context;
private readonly IStringLocalizer<UserRecordsController> _localizer;
public UserRecordsController(theManagerContext context)
{
_context = context;
}
uj5u.com熱心網友回復:
ASP.NET Core 全球化和本地化https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/localization?view=aspnetcore-3.0
uj5u.com熱心網友回復:
我有些不明白,這個應該怎樣改? 原本是theManagerContext type的,我應該用什麼代替? 謝謝
public class UserRecordsController : Controller
{
private readonly theManagerContext _context;
private readonly IStringLocalizer<UserRecordsController> _localizer;
public UserRecordsController(theManagerContext context)
{
_context = context;
}
uj5u.com熱心網友回復:
其實我也不確定是否用IStringLocalizer.....轉載請註明出處,本文鏈接:https://www.uj5u.com/net/102027.html
標籤:C#
下一篇:背景圖片顯示一半
