Fix localizer with async local setter of culture
This commit is contained in:
parent
7bf91a073c
commit
b740317a40
@ -0,0 +1,14 @@
|
||||
using Insight.Localizer;
|
||||
using Insight.TelegramBot.Handling.Handlers;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace Nocr.TelegramClient.AppServices.Handlers;
|
||||
|
||||
public sealed class SetLocalizerCultureHandler : IUpdateHandler
|
||||
{
|
||||
public Task Handle(Update update, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Localizer.CurrentCulture = "ru-ru";
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@ -4,7 +4,6 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Nocr.TelegramClient.AppServices.Bots.MessageDispatcher;
|
||||
using Nocr.TelegramClient.AppServices.Handlers;
|
||||
using Nocr.TelegramClient.AppServices.Handlers.Messages.FeedbackMessage;
|
||||
using Nocr.TelegramClient.AppServices.Options;
|
||||
using Nocr.TelegramClient.AppServices.TextSubscriptions.Handlers;
|
||||
using Nocr.TelegramClient.AppServices.Users;
|
||||
@ -27,6 +26,7 @@ public static class ServiceCollectionExtensions
|
||||
services.AddHttpClient();
|
||||
|
||||
services.Configure<AdministrationOptions>(configuration.GetSection(nameof(AdministrationOptions)));
|
||||
services.AddScoped<IUpdateHandler, SetLocalizerCultureHandler>();
|
||||
services.AddScoped<IUpdateHandler, UpdateTelegramLoggingHandler>();
|
||||
|
||||
services.Configure<UsersRestEaseOptions>(configuration.GetSection(nameof(UsersRestEaseOptions)));
|
||||
|
||||
@ -29,14 +29,9 @@ public class Startup
|
||||
.GetSection(nameof(LocalizerConfiguration))
|
||||
.Get<LocalizerConfiguration>();
|
||||
Localizer.Initialize(localizerConfiguration);
|
||||
services.AddSingleton<ILocalizer, Localizer>();
|
||||
|
||||
services.AddSingleton(new Localizer());
|
||||
// Хак, чтобы постоянно использовать русскую локализацию. В идеале CurrentCulture должен выставляться на основании контекста пользователя в месте инжекта.
|
||||
services.AddScoped<ILocalizer>(ctx =>
|
||||
{
|
||||
Localizer.CurrentCulture = "ru-ru";
|
||||
return ctx.GetRequiredService<Localizer>();
|
||||
});
|
||||
services.AddAppServices(Configuration);
|
||||
|
||||
services.AddSingleton<ICurrentDateProvider, DefaultCurrentDateProvider>();
|
||||
services.AddTelegramBot(bot =>
|
||||
@ -48,8 +43,6 @@ public class Startup
|
||||
.WithPolling(polling => polling.WithExceptionHandler<LoggingPollingExceptionHandler>()));
|
||||
services.AddTelegramBotHandling(typeof(BotClient).Assembly);
|
||||
|
||||
services.AddAppServices(Configuration);
|
||||
|
||||
services.Configure<RebusRabbitMqOptions>(Configuration.GetSection(nameof(RebusRabbitMqOptions)));
|
||||
services.AddRebus((builder, ctx) =>
|
||||
builder.Transport(t =>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user