我想将默认文化“en”更改为“vi”。
但它不起作用。
_Layout.cshtml
<div>
<a href="/?culture=vi" style="margin-right: 16px;">Tiếng Việt</a>
<a href="/?culture=en">English</a>
</div>
<div style="padding:12px;">
<h2>@SharedLocalizer["Welcome"]</h2>
</div>
index.cshtml
@inject IViewLocalizer Localizer;
<div style="padding:32px;">
<h1>Value: @Localizer["Value"]</h1>
</div>
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc().AddViewLocalization().AddDataAnnotationsLocalization();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
List<CultureInfo> supportedCultures = new List<CultureInfo>
{
new CultureInfo("vi"),
new CultureInfo("en"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("vi"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute("default", "{controller=Home}/{action=Index}/{id?}");
});
}
SharedResources.en.resx
SharedResources.vi.resx
Views.Home.Index.en.resx
Views.Home.Index.vi.resx