Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Localization in ".NET MAUI Blazor Hybrid and Web App" not working

$
0
0

I am working with MAUI Blazor 3 projects.

...App (MAUI hosting a Blazor View)

...App.Shared

...App.Web (Blazor Web)

I am having issues getting localization to work in this project. I have tried the following to try to solve the problem.

Program.cs (.Web Project)

builder.Services.AddLocalization(options => options.ResourcesPath = "Resources");var app = builder.Build();var supportedCultures = new[] { "en-GB", "en-US", "fr-FR", "en-ZA" };var localizationOptions = new RequestLocalizationOptions().SetDefaultCulture(supportedCultures[0])    .AddSupportedCultures(supportedCultures)    .AddSupportedUICultures(supportedCultures);app.UseRequestLocalization(localizationOptions);

Resources (.Shared Project)

enter image description here

My Resource file looks like this:

enter image description here

My Component UserMenu is located in the folder Layout > Top.

UserMenu.razor

@inject IStringLocalizer<Resources> Localizer@Localizer["MyProfileLabel"]

Imports.razor

@using ...Shared.Resources

The output is MyProfileLabel


I have tried adding a RootNamespace in the assemblyinfo.cs in both the ...Shared and ...Web projects.

[assembly: RootNamespace("...App.Web")]

I also added the following reference to my ...App.Web & App.Shared project

enter image description here

I also tried to use a middleware to set the cookie on the request.

public class LocalisationMiddleware() : IMiddleware{    public async Task InvokeAsync(HttpContext context, RequestDelegate next)    {        // check if cookie already exists        var cookie = context.Request.Cookies[CookieRequestCultureProvider.DefaultCookieName];        if (cookie != null)        {            context.Response.Cookies.Append(                CookieRequestCultureProvider.DefaultCookieName,                CookieRequestCultureProvider.MakeCookieValue(                    new RequestCulture(                        CultureInfo.CurrentCulture,                        CultureInfo.CurrentUICulture)));        }        await next(context);    }}

The output is MyProfileLabel


The App compiles and runs but no localization.


Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>