Blazor Localization issue with reading .resx

77 Views Asked by At

I have an issue with reading the values from my resx file. I am unsure if it is due to it being unable to find the .resx file, finding the .resx file but not loading it or something else entirely.

Index.Razor

@inject IStringLocalizer<App> Loc

<h1>@greeting</h1>
<h1>@Loc["WelcomeMessage"]</h1>
<b>CurrentCulture</b>: @CultureInfo.CurrentCulture
@code {
    private string? greeting;
    protected override void OnInitialized()
    {
        greeting = Loc["WelcomeMessage"];
    }
}

Program.cs

    builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");
        var locale = new LocalizationHelper(builder.Configuration);

    var app = builder.Build();

    // Configure the HTTP request pipeline.
    if (!app.Environment.IsDevelopment())
    {
        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(locale.GetLocalizationOptions());

Output as follows : (Actual output)

@greeting : WelcomeMessage

@Loc["WelcomeMessage"] : WelcomeMessage

@CultureInfo.CurrentCulture : en-US

However in my App.en-US.resx (Expected output)

DateTime output DOES reflects my CurrentCulture properly. So for zh-SG it gives me the dates in chinese and when en-US it is in english.

Name = "WelcomeMessage" Value = "Hello World!"

I have no idea what could possibly be the issue that the .resx file seems to be completely ignored. The code was working before but this seem to occured after I added Identities and Authorizations to my project but it seems unlikely to be the cause?

0

There are 0 best solutions below