Home > Enterprise >  Changing locale not being applied in Blazor server-side app
Changing locale not being applied in Blazor server-side app

Time:09-01

I have implemented localization of a Blazor Server-side app (NET6) as described enter image description here


Update create two new resource:

enter image description here

Create a new class:

public class SharedResource
{
}

Usage:

@page "/culture-example-2"
@using System.Globalization
@inject IStringLocalizer<SharedResource> Loc

<h1>Culture Example 2</h1>

<p>
    <b>CurrentCulture</b>: @CultureInfo.CurrentCulture
</p>

<h2>Greeting</h2>

<p>
    @Loc["Greeting"]
</p>

<p>
    @greeting
</p>

@code {
    private string? greeting;

    protected override void OnInitialized()
    {
        greeting = Loc["Greeting"];
    }
}
  • Related