[英]how do I set the "app wide" culture of a blazor serverside app to UK
Ive been trying (without success) to change the default culture in my Blazor serverside app to UK format.我一直在尝试(没有成功)将我的 Blazor 服务器端应用程序中的默认文化更改为英国格式。 Ive created an extension method on IApplicationBuilder but it doesnt work, dates are always in US format, heres the extension method我在 IApplicationBuilder 上创建了一个扩展方法,但它不起作用,日期总是美国格式,继承人的扩展方法
public static void UseBrowserLocalisation(this IApplicationBuilder app)
{
var culture = new CultureInfo("en-GB");
CultureInfo.CurrentCulture = culture;
CultureInfo.CurrentUICulture = culture;
}
And this is how ive implemented it in the configure method of Startup这就是我在 Startup 的配置方法中实现它的方式
app.UseBrowserLocalisation();
Can anyone see where Im going wrong here?谁能看到我在这里出错了?
**Update I managed to get it working eventually, I added this code to the Configure method in startup **更新我最终设法让它工作,我将此代码添加到启动时的配置方法中
var localizeoptions = new RequestLocalizationOptions()
.SetDefaultCulture("en-GB")
.AddSupportedCultures("en-US")
.AddSupportedUICultures("en-US");
app.UseRequestLocalization(localizeoptions);
First, use the namespace “using Microsoft.AspNetCore.Builder;”首先,使用命名空间“using Microsoft.AspNetCore.Builder;” in startup.cs file.在 startup.cs 文件中。
Then in “ConfigureServices” method of startup.cs add this code:然后在 startup.cs 的“ConfigureServices”方法中添加以下代码:
public void ConfigureServices(IServiceCollection services)
{
services.Configure<RequestLocalizationOptions>(options =>
{
var CultureInfo = "en-GB";
var supportedCultures = new[] { new CultureInfo(CultureInfo) };
options.DefaultRequestCulture = new RequestCulture(CultureInfo);
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
}
Configure service for default localization in ConfigureServices then add a middleware in the Configure method of startup.cs like this:在 ConfigureServices 中为默认本地化配置服务,然后在 startup.cs 的 Configure 方法中添加一个中间件,如下所示:
app.UseRequestLocalization(app.ApplicationServices.GetService<IOptions<RequestLocalization
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.