我创建了一个简单的剃须刀页面并实现了本地化功能。但这对我不起作用。
Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddLocalization(options => { options.ResourcesPath = "Resources"; });
var supportedCultures = new List<CultureInfo> { new CultureInfo("en"), new CultureInfo("de") };
services.Configure<RequestLocalizationOptions>(options =>
{
options.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("en");
options.SupportedUICultures = supportedCultures;
});
}
// 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();
}
else
{
app.UseExceptionHandler("/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();
app.UseRequestLocalization();
app.UseRouting();
app.ApplicationServices
.UseBootstrapProviders()
.UseFontAwesomeIcons();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
Localization.razor:
@页面“ /” @using Microsoft.Extensions.Localization
@localizer [“内容”]
@code { [注入] 公共Microsoft.Extensions.Localization.IStringLocalizer本地化器{组; } }
Localization.resx:
结果:
我没有获得确切的资源价值。请帮我解决这个问题?
谢谢。