Added localization addon

This commit is contained in:
gutii
2026-02-27 19:18:18 +04:00
parent e77894fde6
commit 5a3640bc9f
22 changed files with 172 additions and 61 deletions
+11
View File
@@ -0,0 +1,11 @@
using Microsoft.Extensions.Localization;
using Telegram.Bot.Types;
using Telegrator.Handlers.Components;
namespace Telegrator.Localized
{
public interface ILocalizedHandler<T> : IAbstractUpdateHandler<Message> where T : class
{
public IStringLocalizer LocalizationProvider { get; }
}
}
@@ -0,0 +1,10 @@
using Telegram.Bot.Types;
using Telegrator.Handlers.Components;
namespace Telegrator.Localized
{
public interface ILocalizedMessageHandler : ILocalizedHandler<Message>
{
}
}
@@ -0,0 +1,17 @@
using Microsoft.Extensions.Localization;
using System.Collections.Generic;
using System.Threading.Tasks;
using Telegram.Bot.Types;
using Telegrator.Handlers;
namespace Telegrator.Localized
{
public static class LocalizedMessageHandlerExtensions
{
public static async Task<Message> ResponseLocalized(this ILocalizedHandler<Message> localizedHandler, string localizedReplyIdentifier, params IEnumerable<string> formatArgs)
{
LocalizedString localizedString = localizedHandler.LocalizationProvider[localizedReplyIdentifier];
localizedHandler.Container.Response();
}
}
}
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="10.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Telegrator\Telegrator.csproj" />
</ItemGroup>
</Project>