Blazor Server应用程序-本地化不起作用

时间:2020-10-14 11:09:32

标签: blazor-server-side

我创建了一个简单的剃​​须刀页面并实现了本地化功能。但这对我不起作用。

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 [“标题”]

@localizer [“内容”]

@code { [注入] 公共Microsoft.Extensions.Localization.IStringLocalizer本地化器{组; } }

Localization.resx:

enter image description here

结果:

enter image description here

我没有获得确切的资源价值。请帮我解决这个问题?

谢谢。

0 个答案:

没有答案