I'm trying to add Localization in my serverside Blazor app. I have a seperate project which contains my Resource files for NL and EN.
My Startup.cs of my UI project(ConfigureServices)
services.AddLocalization();
services.Configure<RequestLocalizationOptions>(options =>
{
List<CultureInfo> supportedCultures =
new List<CultureInfo>
{
new CultureInfo("nl"),
new CultureInfo("en")
};
options.DefaultRequestCulture = new RequestCulture("nl");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
Blazor file in my UI project:
@inject IStringLocalizer<Menu> MenuLocalizer
@MenuLocalizer["Overview"]
@MenuLocalizer["Add"]
But the Localization from the resources never gets taken. Changing the DefaultRequestCulture in startup doesn't also change anything.
I have searched on the net and it looks like I'm doing everything as it should, but no result.
EDIT: I've made some changes to my resource files, added an explicit NL file. It seems that the localization always takes the EN version although I specify NL in my StartUp.
So it looks like the localization is working, but not taking the correct file.
EDIT 2: Fixed it by adding:
options.RequestCultureProviders = new List<IRequestCultureProvider>
{
new QueryStringRequestCultureProvider(),
new CookieRequestCultureProvider()
};
Now it takes the file defined in the startup.