- (Maui хостинга в Blazor)
Код: Выделить всё
App
Код: Выделить всё
App.Shared
- (blazor web)
Код: Выделить всё
App.Web
Код: Выделить всё
Program.cs
Код: Выделить всё
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);
my recarce file выглядит как следующее: alt = "Введите описание изображения здесь" src = "https://i.sstatic.net/iyepgavw.png"/>
my component usermenu находится в папке "Layout> top".
Код: Выделить всё
UserMenu.razor
Код: Выделить всё
@inject IStringLocalizer Localizer
@Localizer["MyProfileLabel"]
< /code>
Imports.razor
Код: Выделить всё
@using ...Shared.Resources
< /code>
The output is [b]MyProfileLabel[/b].
I have tried adding a RootNamespace
Код: Выделить всё
[assembly: RootNamespace("...App.Web")]
< /code>
I also added the following reference to my App.Web
Я также пытался использовать промежуточное лицо, чтобы установить поужина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);
}
}
< /code>
The output is MyProfileLabel
The app compiles and runs, but does not do localization.
Подробнее здесь: https://stackoverflow.com/questions/797 ... ot-working