Код: Выделить всё
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 recruction file выглядит как: . Описание изображения здесь "src =" https://i.sstatic.net/iyepgavw.png "/>
my component usermenu находится в папке layout> top .
** usermen@inject IStringLocalizer Localizer
@Localizer["MyProfileLabel"]
< /code>
** imports.razor ** < /p>
@using ...Shared.Resources
< /code>
Вывод myprofileLabel < /strong> < /p>
Я пытался добавить rootnamespace в Assemblyinfo.cs в обоих ... общих и ... веб -проектах. Rootnamespace ("... app.web")]
Я также добавил следующую ссылку на мой ... app.web & app.shared project
промежуточное программное обеспечение, чтобы установить файл cookie на запросе. < /p>
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>
Вывод myprofilelabel < /strong> < /p>
Приложение компилирует и работает, но не локализация. < /p>
Подробнее здесь: https://stackoverflow.com/questions/797 ... nd-web-app