Добавляет локализацию (#4)
Reviewed-on: #4 Co-authored-by: Sergey Nazarov <insight.appdev@gmail.com> Co-committed-by: Sergey Nazarov <insight.appdev@gmail.com>
This commit is contained in:
parent
25e095ed82
commit
ba8c94d962
@ -6,6 +6,9 @@
|
|||||||
<MicrosoftVersion>8.0.0</MicrosoftVersion>
|
<MicrosoftVersion>8.0.0</MicrosoftVersion>
|
||||||
<InsightTelegramBotVersion>0.16.0</InsightTelegramBotVersion>
|
<InsightTelegramBotVersion>0.16.0</InsightTelegramBotVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageVersion Include="Insight.Localizer" Version="1.1.0"/>
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup Label="Nocr">
|
<ItemGroup Label="Nocr">
|
||||||
<PackageVersion Include="Nocr.TextMatcher.Api.Contracts" Version="0.4.25"/>
|
<PackageVersion Include="Nocr.TextMatcher.Api.Contracts" Version="0.4.25"/>
|
||||||
<PackageVersion Include="Nocr.TextMatcher.Async.Api.Contracts" Version="0.4.25"/>
|
<PackageVersion Include="Nocr.TextMatcher.Async.Api.Contracts" Version="0.4.25"/>
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using Insight.Localizer;
|
||||||
using Insight.TelegramBot;
|
using Insight.TelegramBot;
|
||||||
using Insight.TelegramBot.Handling.Handlers;
|
using Insight.TelegramBot.Handling.Handlers;
|
||||||
using Insight.TelegramBot.Models;
|
using Insight.TelegramBot.Models;
|
||||||
@ -9,10 +10,12 @@ namespace Nocr.TelegramClient.AppServices.Handlers.Messages.StartMessage;
|
|||||||
|
|
||||||
public class StartMessageHandler : IMatchingUpdateHandler<StartMessageMatcher>
|
public class StartMessageHandler : IMatchingUpdateHandler<StartMessageMatcher>
|
||||||
{
|
{
|
||||||
|
private readonly ILocalizer _localizer;
|
||||||
private readonly IMessageDispatcherQueue _messageQueue;
|
private readonly IMessageDispatcherQueue _messageQueue;
|
||||||
|
|
||||||
public StartMessageHandler(IMessageDispatcherQueue messageQueue)
|
public StartMessageHandler(ILocalizer localizer, IMessageDispatcherQueue messageQueue)
|
||||||
{
|
{
|
||||||
|
_localizer = localizer ?? throw new ArgumentNullException(nameof(localizer));
|
||||||
_messageQueue = messageQueue ?? throw new ArgumentNullException(nameof(messageQueue));
|
_messageQueue = messageQueue ?? throw new ArgumentNullException(nameof(messageQueue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +24,7 @@ public class StartMessageHandler : IMatchingUpdateHandler<StartMessageMatcher>
|
|||||||
var telegramId = update.Message.From.Id;
|
var telegramId = update.Message.From.Id;
|
||||||
var message = new TextMessage(telegramId)
|
var message = new TextMessage(telegramId)
|
||||||
{
|
{
|
||||||
Text = "Привет! Я _bot_name_",
|
Text = _localizer.Get("messages", "StartMessage"),
|
||||||
ParseMode = ParseMode.Html
|
ParseMode = ParseMode.Html
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -44,6 +44,7 @@ public class SubscribeMessageHandler : IMatchingUpdateHandler<SubscribeMessageMa
|
|||||||
{
|
{
|
||||||
_messageQueue.Enqueue(new TextMessage(telegramId)
|
_messageQueue.Enqueue(new TextMessage(telegramId)
|
||||||
{
|
{
|
||||||
|
// TODO: Add localizer
|
||||||
Text = "Команда не удовлетворяет формату"
|
Text = "Команда не удовлетворяет формату"
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -54,6 +55,7 @@ public class SubscribeMessageHandler : IMatchingUpdateHandler<SubscribeMessageMa
|
|||||||
{
|
{
|
||||||
_messageQueue.Enqueue(new TextMessage(telegramId)
|
_messageQueue.Enqueue(new TextMessage(telegramId)
|
||||||
{
|
{
|
||||||
|
// TODO: Add localizer
|
||||||
Text = "Не удалось извлечь тип подписки"
|
Text = "Не удалось извлечь тип подписки"
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
@ -72,6 +74,7 @@ public class SubscribeMessageHandler : IMatchingUpdateHandler<SubscribeMessageMa
|
|||||||
|
|
||||||
_messageQueue.Enqueue(new TextMessage(telegramId)
|
_messageQueue.Enqueue(new TextMessage(telegramId)
|
||||||
{
|
{
|
||||||
|
// TODO: Add localizer
|
||||||
Text = $"Подписка создана: {subscriptionId}"
|
Text = $"Подписка создана: {subscriptionId}"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -36,6 +36,7 @@ public class SubscriptionsMessageHandler : IMatchingUpdateHandler<SubscriptionsM
|
|||||||
{
|
{
|
||||||
var textMessage = new TextMessage(telegramId)
|
var textMessage = new TextMessage(telegramId)
|
||||||
{
|
{
|
||||||
|
// TODO: Add localizer
|
||||||
Text = subscription.TextView(),
|
Text = subscription.TextView(),
|
||||||
ParseMode = ParseMode.Html
|
ParseMode = ParseMode.Html
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Insight.Localizer" />
|
||||||
<PackageReference Include="Insight.TelegramBot" />
|
<PackageReference Include="Insight.TelegramBot" />
|
||||||
<PackageReference Include="Insight.TelegramBot.Handling" />
|
<PackageReference Include="Insight.TelegramBot.Handling" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Http" />
|
<PackageReference Include="Microsoft.Extensions.Http" />
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
using Insight.Localizer;
|
||||||
using Insight.TelegramBot.Handling.Infrastructure;
|
using Insight.TelegramBot.Handling.Infrastructure;
|
||||||
using Insight.TelegramBot.Hosting.DependencyInjection.Infrastructure;
|
using Insight.TelegramBot.Hosting.DependencyInjection.Infrastructure;
|
||||||
using Insight.TelegramBot.Hosting.Polling.ExceptionHandlers;
|
using Insight.TelegramBot.Hosting.Polling.ExceptionHandlers;
|
||||||
@ -24,6 +25,19 @@ public class Startup
|
|||||||
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
|
var localizerConfiguration = Configuration
|
||||||
|
.GetSection(nameof(LocalizerConfiguration))
|
||||||
|
.Get<LocalizerConfiguration>();
|
||||||
|
Localizer.Initialize(localizerConfiguration);
|
||||||
|
|
||||||
|
services.AddSingleton(new Localizer());
|
||||||
|
// Хак, чтобы постоянно использовать русскую локализацию. В идеале CurrentCulture должен выставляться на основании контекста пользователя в месте инжекта.
|
||||||
|
services.AddScoped<ILocalizer>(ctx =>
|
||||||
|
{
|
||||||
|
Localizer.CurrentCulture = "ru-ru";
|
||||||
|
return ctx.GetRequiredService<Localizer>();
|
||||||
|
});
|
||||||
|
|
||||||
services.AddSingleton<ICurrentDateProvider, DefaultCurrentDateProvider>();
|
services.AddSingleton<ICurrentDateProvider, DefaultCurrentDateProvider>();
|
||||||
services.AddTelegramBot(bot =>
|
services.AddTelegramBot(bot =>
|
||||||
bot.WithBot<BotClient>(ServiceLifetime.Transient)
|
bot.WithBot<BotClient>(ServiceLifetime.Transient)
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
<Content Include="..\..\.dockerignore">
|
<Content Include="..\..\.dockerignore">
|
||||||
<Link>.dockerignore</Link>
|
<Link>.dockerignore</Link>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="Resources" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"Delete": "Delete 🧹",
|
||||||
|
"PreviousPage": "<<",
|
||||||
|
"NextPage": ">>",
|
||||||
|
"Back": "<< Back"
|
||||||
|
}
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"Delete": "Удалить 🧹",
|
||||||
|
"PreviousPage": "<<",
|
||||||
|
"NextPage": ">>",
|
||||||
|
"Back": "<< Назад"
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"InvalidTimeFormat": "Time <b>{ReceivedTime}</b> does not correspond to the acceptable formats!",
|
||||||
|
"InvalidDateFormat": "Date <b>{ReceivedDate}</b> does not correspond to the acceptable formats!"
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"InvalidTimeFormat": "Время <b>{ReceivedTime}</b> не соответствует допустимым форматам!",
|
||||||
|
"InvalidDateFormat": "Дата <b>{ReceivedDate}</b> не соответствует допустимым форматам!"
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"en-us": "🇬🇧",
|
||||||
|
"ru-ru": "🇷🇺"
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"English": "English 🇬🇧",
|
||||||
|
"Russian": "Русский 🇷🇺"
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"English": "English 🇬🇧",
|
||||||
|
"Russian": "Русский 🇷🇺"
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"StartMessage": "Привет! Я, Nocr 🤖!"
|
||||||
|
}
|
||||||
@ -17,5 +17,10 @@
|
|||||||
"MessageDispatcherOptions": {
|
"MessageDispatcherOptions": {
|
||||||
"Interval": "00:00:00.050",
|
"Interval": "00:00:00.050",
|
||||||
"ExceptionInterval": "00:00:30"
|
"ExceptionInterval": "00:00:30"
|
||||||
|
},
|
||||||
|
"LocalizerConfiguration": {
|
||||||
|
"Path": "Resources",
|
||||||
|
"Pattern": "",
|
||||||
|
"ReadNestedFolders": "true"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user