这是由于Blazor客户端的语言环境没有被正确处理而导致的。为了解决这个问题,需要在客户端的Startup.cs文件中添加以下代码:
using System.Globalization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace BlazorApp.Client
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddLocalization(options =>
{
options.ResourcesPath = "Resources";
});
services.Configure(options =>
{
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("fr-FR"),
new CultureInfo("es-ES"),
new CultureInfo("pt-BR"),
new CultureInfo("zh-CN"),
new CultureInfo("ja-JP"),
new CultureInfo("ko-KR")
};
options.DefaultRequestCulture = new RequestCulture("en-US");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("fr-FR"),
new CultureInfo("es-ES"),
new CultureInfo("pt-BR"),
new CultureInfo("zh-CN"),
new CultureInfo("ja-JP"),
new CultureInfo("ko-KR")
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-US"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
if (env.IsDevelopment())
{
app.UseWebAssemblyDebugging();
}
app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToFile("index.html");
});
}
}
}
然后,在项目的Resources文件夹中创建一个名为"SharedResources.xx-XX.resx"的
上一篇:Blazor客户端调试失败