嗨,我正在尝试在.net core中实现本地化。我想在我的视图静态内容中实现本地化。默认情况下,它将显示德语,也可以更改为其他语言。我已将其配置为将默认区域性设置为德语,但无法正常工作。请帮助
我尝试过的是:-
在我的启动文件中
public void ConfigureServices(IServiceCollection services)
{
//adding HttpContextAccessor middleware
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddRouting(options => options.LowercaseUrls = true);
services.AddMvc();
//configuration for multilanguage support
services.AddLocalization();
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
//adding other services...
ConfigureBusinessServices(services);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
var supportedCultures = new[]{
new CultureInfo("en-US"),
new CultureInfo("fr"),
new CultureInfo("de"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("de"),
// Formatting numbers, dates, etc.
SupportedCultures = supportedCultures,
// UI strings that we have localized.
SupportedUICultures = supportedCultures
});
app.UseStaticFiles();
app.UseSession();
//configuring mvc routes...
app.UseMvc(routes =>
{
routes.MapRoute(
name: "areaRoute",
template: "{area:exists}/{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}",
defaults: new { controller = "Home", action = "Index" });
});
}
在我看来,我已经做到了:-
@TestProject.Resources.TestProjectUI.Home.ContactUs.btn_TextSendMessage
显示资源价值
我正在从资源文件中获取数据,但从英语资源文件中获取数据,因为当前的文化设置为英语英国。我得到这样的输出:
当前的区域性显示为英语,因为消息(发送消息英语区域性)来自En.resx文件。